向其他命令行程序发送命令
有没有办法将命令发送到另一个命令行程序?
因为我有一个特殊的命令行程序,但我无法使用诸如 program.exe Something_to_do
之类的语法向其发送命令,
该程序执行如下所示的内容:(“此处语法”是我想要的输入文本并输入开始)
TheWhateverCommandLineProgram
Version 1.1
Give an option: "here syntax"
代码中的程序看起来像这样:
echo TheWhateverCommandLineProgram
echo Version 1.1
Set opt=
set /p opt=Give an option:
if %opt%==command1 goto com1
if %opt%==command2 goto com2
...
嗯,我想是这样,因为不是我制作的(顺便说一句:当然它不叫 TheWhateverCommandLineProgram)
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
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只想向命令行程序提供键盘输入,您可以使用 echo 并通过管道传输:
如果您需要更多行,请将它们写入文件并使用输入重定向:
If you just want to give keyboard input to a commandline program you can just use
echo
and pipe it:If you need more lines, then write them to a file and use input redirection:
我不能 100% 确定我明白你在寻找什么。 这里有两个选项:
您有两个窗口,每个窗口都运行一个批处理程序。 假设它们名为
myscript1.bat
和myscript2.bat
。 您想要从myscript1.bat
发送一组由myscript2.bat
执行的命令
您有一个名为
myscript.bat< 的批处理脚本/code>,它执行名为
program.exe
的单个程序。 您希望program.exe
执行一些命令,或者做一些事情。您正在寻找其中的任何一个吗? 这里有一些想法:
让
myscript1.bat
创建第三个文件mycommands.bat
。 一旦myscript2.bat
发现文件mycommands.bat
存在,它就会执行它并删除它。 (哇。真蹩脚。)使用 Windows Scripting Host 命令(它自 Win2K 起内置于 Windows)或 Powershell(通常在当今大多数计算机上,如果它们已更新)。 其中任何一个都可以将击键发送到另一个程序。 使用这些击键,您可以控制其他程序。
I'm not 100% sure I understand what you're looking for. Here's two options:
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.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.
其他程序以什么形式接受输入? 从命令提示符?
如果是后者,那么我推荐 Autohotkey: http://www.autohotkey.com/
您可以使用 Autohotkey 作为一个桥接器,它将把命令作为按键发送到另一个批处理文件的窗口。
您可以在他们的论坛中寻求帮助。 他们非常有帮助。
In what form does the other program take input? From the command prompt?
If the latter then I recommend 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.
You can ask for help in their forum. They are quite helpful.