向其他命令行程序发送命令

发布于 2024-07-29 16:52:40 字数 524 浏览 12 评论 0原文

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

因为我有一个特殊的命令行程序,但我无法使用诸如 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 技术交流群。

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

发布评论

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

评论(3

自我难过 2024-08-05 16:52:40

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

echo some text | program.exe

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

echo one line > file
echo second line >> file
program.exe < file

If you just want to give keyboard input to a commandline program you can just use echo and pipe it:

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
白首有我共你 2024-08-05 16:52:40

我不能 100% 确定我明白你在寻找什么。 这里有两个选项:

  1. 您有两个窗口,每个窗口都运行一个批处理程序。 假设它们名为 myscript1.batmyscript2.bat。 您想要从 myscript1.bat 发送一组由 myscript2.bat

    执行的命令

  2. 您有一个名为 myscript.bat< 的批处理脚本/code>,它执行名为 program.exe 的单个程序。 您希望 program.exe 执行一些命令,或者做一些事情。

您正在寻找其中的任何一个吗? 这里有一些想法:

  1. myscript1.bat 创建第三个文件 mycommands.bat。 一旦myscript2.bat发现文件mycommands.bat存在,它就会执行它并删除它。 (哇。真蹩脚。)

  2. 使用 Windows Scripting Host 命令(它自 Win2K 起内置于 Windows)或 Powershell(通常在当今大多数计算机上,如果它们已更新)。 其中任何一个都可以将击键发送到另一个程序。 使用这些击键,您可以控制其他程序。

I'm not 100% sure I understand what you're looking for. Here's two options:

  1. You have two windows, each running a batch program. Let's say they are called myscript1.bat and myscript2.bat. You want to send a set of commands from myscript1.bat to be executed by myscript2.bat

  2. You have a single batch script named myscript.bat, which executes a single program named program.exe. You want program.exe to execute some commands, or do some something.

Are either of these what you're looking for? Here's some idea:

  1. Make myscript1.bat create a third file, mycommands.bat. Once myscript2.bat sees the file mycommands.bat exists, it will execute it and delete it. (Wow. Lame.)

  2. 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.

握住你手 2024-08-05 16:52:40

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

如果是后者,那么我推荐 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.

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