Batch Script to Automate a DOS Program with Options

拈花ヽ惹草 提交于 2019-12-21 19:39:59

问题


I have a console program ( a DOS program) that requires interactive input. After typing in the command line, for example

commandline.exe /ShowReport

The DOS prompt will prompt user to key in some values, and then proceed to the next interactive input.

For example, when I typed in the above command, the console will prompt me with the following options:

press '1' to show Report A
press '2' to Show Report B

And I would press '1' if I want to show report A.

The issue now is I want to automate all these things by presetting all the input values in a script files. Maybe something like this ( I don't know)

commandline.exe /ShowReport <1<'abc'

I want to write a batch script for this. Is there any tools that allow me to do that?


回答1:


You could write all your inputs in a file (say 'input.txt') and use redirection to feed your program with these inputs:

commandline.exe /ShowReport < input.txt

The '<' tells the command prompt to use the content of the file on the right hand side as standard input.




回答2:


Not strictly a batch solution but this might do the trick: Expect

See also the Wikipedia entry.



来源:https://stackoverflow.com/questions/926696/batch-script-to-automate-a-dos-program-with-options

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