如何发送输入到控制台好像用户正在输入? [英] How to send input to the console as if the user is typing?
问题描述
这是我的问题。我有一个程序,有一个TTY运行的cygwin提供了这种TTY。当我重定向标准输入程序失败,因为它没有一个TTY。我不能修改这个程序,并且需要自动化它的一些方法。
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.
我怎么能抢cmd.exe窗口和发送数据,使之认为用户在打字呢?
我使用C#,我相信有一种方法可以用java.awt.Robot中做到这一点,但我要使用C#的其他原因。
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.
推荐答案
这听起来像的 的SendKeys()
。这不是C#,但VBScript中,但nontheless - 你问的自动化它一定的方式:
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}"
这篇关于如何发送输入到控制台好像用户正在输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!