简体   繁体   English

如何从 c++ 向 cmd.exe 发送一串字符?

[英]How can I send a chain of characters to a cmd.exe from c++?

I tried with findwindow and sendmessage, but, with sendmessage I only can send message for the GUI.我尝试使用 findwindow 和 sendmessage,但是,使用 sendmessage 我只能为 GUI 发送消息。 Help!!!!!帮助!!!!!

Try to use the keybd_event function. It's not very friendly so if you want to use it for complex tasks you may take a look to this library on CodeProject that emulates the well-known SendKey command for VBScript/.NET.尝试使用keybd_event function。它不是很友好,所以如果您想将它用于复杂的任务,您可以看看 CodeProject 上的这个库,它模拟了 VBScript/.NET 的众所周知的SendKey命令。

I think that best way to start command line process using CreateProcess function that takes STARTUPINFO structure with input / output handles specified.我认为使用 CreateProcess function 启动命令行进程的最佳方法采用 STARTUPINFO 结构并指定输入 / output 句柄。

When cmd process is already started use SendInput.当 cmd 进程已经启动时,使用 SendInput。 But IMHO this way is less reliable.但是恕我直言,这种方式不太可靠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM