如何将输入发送到控制台,就像用户正在打字一样? [英] How to send input to the console as if the user is typing?

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

问题描述

这是我的问题.我有一个必须在 TTY 中运行的程序,cygwin 提供了这个 TTY.当我重定向 stdIn 时,程序失败,因为它没有 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,但尽管如此 - 您要求某种自动化方法:

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆