使用 .bat 文件编写 msdos 程序脚本

发布于 2024-10-01 01:30:08 字数 127 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薔薇婲 2024-10-08 01:30:08

如果答案始终相同,您可以(通常)将标准输入重定向到包含答案的文本文件(每行一个,最后一个答案后应该有一个换行符)

Program.exe -option1 -option2 < answers.txt

我说“经常”是因为有些程序会围绕标准输入的代码,例如“runas”。

answers.txt 看起来像这样:

answer1
answer2
answer3

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)

Program.exe -option1 -option2 < answers.txt

I say "often" because some programs will code around the standard input, like "runas".

answers.txt just looks like this:

answer1
answer2
answer3
遗失的美好 2024-10-08 01:30:08

为了编写批处理脚本来自动执行此任务,您必须使用模拟 dos 中击键的程序,例如 key-fake。

另一种方法是使用本身具有此功能的 Windows Script Host。

示例脚本(在 javascript 中)类似于:

var objShell = WScript.CreateObject("WScript.Shell");
var answer1 = a, answer2 = b, answer3 = c;


while(true) {
    var myProg = Wscript.Exec("MyProgram");

    WScript.Sleep = 100;

    WScript.Echo(answer1);
    WScript.SendKeys("{Enter}"); //Simulate Enter key
    WScript.Echo(answer2);
    WScript.SendKeys("{Enter}");
    WScript.Echo(answer3);
    WScript.SendKeys("{Enter}");
}

将脚本另存为 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:

var objShell = WScript.CreateObject("WScript.Shell");
var answer1 = a, answer2 = b, answer3 = c;


while(true) {
    var myProg = Wscript.Exec("MyProgram");

    WScript.Sleep = 100;

    WScript.Echo(answer1);
    WScript.SendKeys("{Enter}"); //Simulate Enter key
    WScript.Echo(answer2);
    WScript.SendKeys("{Enter}");
    WScript.Echo(answer3);
    WScript.SendKeys("{Enter}");
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文