automate a windows command line utility with a batch file - send keystrokes to std input after utility starts

廉价感情. 提交于 2019-12-12 15:43:34

问题


I have a command line utility which opens a serial connection specified by args sent in (duh) the command line. After the utility starts, I can type into the std input to send strings to the port to which I am connected. What I would like to do is start the utility with a batch file (easy enough), then automate the keystrokes I wish to send. I am having no luck on my own and need some expert advice.

I'll give a more specific example: I start teraterm.exe (opensource serial communication utility) in a batch file with this line: "call serialterm com5 115200 ascii yes" Then, I can type "Hello World " and receive the response from the open port. I want the next line in my batch file to send "Hello World " for me, so that I can issue other string commands by listing them in the batch file.

Help is greatly appreciated!

-Matt


回答1:


To automate this, a batch file is not the perfect solution(And I'm one of the batch fanatics), as it is not possible to send keystrokes.
You could switch to JScript/VBscript (possible to send keystrokes, but it's tricky and not very reliable).

But I would recommend a tool like AutoIt, as it can do such things very good.




回答2:


Put the commands in another file and use the < redirection operator.



来源:https://stackoverflow.com/questions/5722605/automate-a-windows-command-line-utility-with-a-batch-file-send-keystrokes-to-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!