将命令发送到其他命令行程序

Den*_*man 4 windows command batch-file send

有没有办法将命令发送到另一个命令行程序?

因为我有一个特殊的命令行程序,但是我无法使用类似的语法向它发送命令 program.exe something_to_do

该程序执行类似这样的操作:(“这里语法”是我要向其输入文本并也要开始输入的位置)

TheWhateverCommandLineProgram
Version 1.1
Give an option: "here syntax"
Run Code Online (Sandbox Code Playgroud)

代码中的程序如下所示:

echo TheWhateverCommandLineProgram
echo Version 1.1
Set opt=
set /p opt=Give an option: 
if %opt%==command1 goto com1
if %opt%==command2 goto com2
...
Run Code Online (Sandbox Code Playgroud)

好吧,我想这是因为不是我做的(顺便说一句:当然,它不叫TheWhateverCommandLineProgram)

Joe*_*oey 5

如果您只想将键盘输入提供给命令行程序,则可以使用echo并通过管道将其输入:

echo some text | program.exe
Run Code Online (Sandbox Code Playgroud)

如果需要更多行,则将它们写入文件并使用输入重定向:

echo one line > file
echo second line >> file
program.exe < file
Run Code Online (Sandbox Code Playgroud)


小智 0

其他程序以什么形式接受输入?从命令提示符?

如果是后者那么我推荐 Autohotkey: http: //www.autohotkey.com/

您可以使用 Autohotkey 作为桥梁,它将命令作为按键发送到另一个批处理文件的窗口。

您可以在他们的论坛中寻求帮助。他们非常有帮助。