问题
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