windows 向其他命令行程序发送命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1198771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send commands to other command-line programs
提问by Deniz Zoeteman
Is there a way, to send commands to another command-line program?
有没有办法将命令发送到另一个命令行程序?
'Cause i have a special command-line program, but I can't send commands to it using syntax like program.exe something_to_do
因为我有一个特殊的命令行程序,但我无法使用类似的语法向它发送命令 program.exe something_to_do
the program executes something like this: ("here syntax" is where i want to input text to and also enter to start)
程序执行如下:(“这里的语法”是我想输入文本并输入开始的地方)
TheWhateverCommandLineProgram
Version 1.1
Give an option: "here syntax"
the program in code looks something like this:
代码中的程序如下所示:
echo TheWhateverCommandLineProgram
echo Version 1.1
Set opt=
set /p opt=Give an option:
if %opt%==command1 goto com1
if %opt%==command2 goto com2
...
Well, i guess so cause it wasnt me who made it (btw: off course its not called TheWhateverCommandLineProgram)
好吧,我想是因为它不是我做的(顺便说一句:当然它不叫 TheWhateverCommandLineProgram)
回答by Joey
If you just want to give keyboard input to a commandline program you can just use echo
and pipe it:
如果您只想将键盘输入提供给命令行程序,您可以使用echo
并通过管道传输它:
echo some text | program.exe
If you need more lines, then write them to a file and use input redirection:
如果需要更多行,请将它们写入文件并使用输入重定向:
echo one line > file
echo second line >> file
program.exe < file
回答by Shalom Craimer
I'm not 100% sure I understand what you're looking for. Here's two options:
我不是 100% 确定我明白你在找什么。这里有两个选项:
You have two windows, each running a batch program. Let's say they are called
myscript1.bat
andmyscript2.bat
. You want to send a set of commands frommyscript1.bat
to be executed bymyscript2.bat
You have a single batch script named
myscript.bat
, which executes a single program namedprogram.exe
. You wantprogram.exe
to execute some commands, or do some something.
您有两个窗口,每个窗口都运行一个批处理程序。假设它们被称为
myscript1.bat
andmyscript2.bat
。你想发送一组命令myscript1.bat
来执行myscript2.bat
您有一个名为 的批处理脚本
myscript.bat
,它执行名为 的单个程序program.exe
。你想program.exe
执行一些命令,或者做一些事情。
Are either of these what you're looking for? Here's some idea:
您正在寻找其中任何一个吗?这里有一些想法:
Make
myscript1.bat
create a third file,mycommands.bat
. Oncemyscript2.bat
sees the filemycommands.bat
exists, it will execute it and delete it. (Wow. Lame.)Use Windows Scripting Host command (it's built in to Windows since Win2K) or Powershell (usually on most computers nowadays, if they have been updated). Either of these can send keystrokes to another program. Using those keystrokes, you can control the other program.
使
myscript1.bat
创建第三个文件,mycommands.bat
。一旦myscript2.bat
看到文件mycommands.bat
存在,它就会执行它并删除它。(哇。跛脚。)使用 Windows Scripting Host 命令(它自 Win2K 起就内置于 Windows 中)或 Powershell(通常在当今大多数计算机上,如果它们已更新)。其中任何一个都可以将击键发送到另一个程序。使用这些按键,您可以控制其他程序。
回答by Shalom Craimer
In what form does the other program take input? From the command prompt?
另一个程序以什么形式接受输入?从命令提示符?
If the latter then I recommend Autohotkey: http://www.autohotkey.com/
如果是后者,那么我推荐 Autohotkey:http://www.autohotkey.com/
You can use Autohotkey as a bridge and it will send the command as keypresses to the window of the other batch file.
您可以使用 Autohotkey 作为桥梁,它将命令作为按键发送到另一个批处理文件的窗口。
You can ask for help in their forum. They are quite helpful.
您可以在他们的论坛中寻求帮助。他们很有帮助。