使用 .bat 文件编写 msdos 程序脚本
我有一个 msdos 程序,当你执行它时,他会要求你输入 3 个文本,你需要回答第一个,按 Enter 键,然后是第二个,按 Enter 键,然后...
我认为答案总是相同的,如何我可以使用 .bat 文件编写脚本吗?谢谢!
i have a msdos program that when you execute it he ask you for 3 texts, you need to answer the firts, hit enter, then the second, hit enter and soo...
The think is that the answers are always the same, how using a .bat file can i script that? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果答案始终相同,您可以(通常)将标准输入重定向到包含答案的文本文件(每行一个,最后一个答案后应该有一个换行符)
我说“经常”是因为有些程序会围绕标准输入的代码,例如“runas”。
answers.txt 看起来像这样:
If the answers are always the same, you can (often) redirect the standard input to a text file containing the answers (one on each line, and there should be a newline after the last answer)
I say "often" because some programs will code around the standard input, like "runas".
answers.txt just looks like this:
为了编写批处理脚本来自动执行此任务,您必须使用模拟 dos 中击键的程序,例如 key-fake。
另一种方法是使用本身具有此功能的 Windows Script Host。
示例脚本(在 javascript 中)类似于:
将脚本另存为 myscript.js。
在 dos 提示符下运行以下命令:
cscript myscript.js
当您希望脚本停止时,按 control-c 来终止该脚本。
为了帮助您根据需要自定义此脚本,您可以获取更多信息 这里。
In order to write a batch script to automate this task you would have to use a program that simulates key strokes in dos such as key-fake.
An alternative would be to use Windows Script Host which has this ability natively.
An example script (in javascript) would be something like:
Save the script as myscript.js.
At a dos prompt run the following command:
cscript myscript.js
Press control-c to kill the script when you want it to stop.
To help you customize this script to your needs you can get more information here.