就像用户正在输入

就像用户正在输入

本文介绍了如何将输入发送到控制台,就像用户正在输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题。我有一个程序,必须运行在TTY,cygwin提供这个TTY。当我重定向stdIn的程序失败,因为它没有TTY。我不能修改这个程序,并需要一些自动化的方法。



我如何获取cmd.exe窗口并发送数据,并认为用户正在键入它? b
$ b

我使用C#,我相信有一个方法可以做到与java.awt.Robot,但我必须使用C#的其他原因。

解决方案

这听起来像是。它不是C#,而是VBScript,但仍然 - 你要求一些自动化的方式:

  Set Shell = CreateObject(WScript.Shell)

Shell.Runcmd.exe / k title RemoteControlShell
WScript.Sleep 250

Shell.AppActivate RemoteControlShell
WScript.Sleep 250

Shell.SendKeysdir {ENTER}


This is my problem. I have a program that has to run in a TTY, cygwin provides this TTY. When I redirect stdIn the program fails because it does not have a TTY. I cannot modify this program, and need some way of automating it.

How can I grab the cmd.exe window and send it data and make it think the user is typing it?

I'm using C#, I believe there is a way to do it with java.awt.Robot but I have to use C# for other reasons.

解决方案

This sounds like a task for SendKeys(). It's not C#, but VBScript, but nontheless - you asked for some way of automating it:

Set Shell = CreateObject("WScript.Shell")

Shell.Run "cmd.exe /k title RemoteControlShell"
WScript.Sleep 250

Shell.AppActivate "RemoteControlShell"
WScript.Sleep 250

Shell.SendKeys "dir{ENTER}"

这篇关于如何将输入发送到控制台,就像用户正在输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:40