Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何使用单个批处理文件运行某个应用程序,并将自己的输入重定向到该文件?_Batch File_Cmd - Fatal编程技术网

Batch file 如何使用单个批处理文件运行某个应用程序,并将自己的输入重定向到该文件?

Batch file 如何使用单个批处理文件运行某个应用程序,并将自己的输入重定向到该文件?,batch-file,cmd,Batch File,Cmd,有一个例子(比如在一个名为mybatch.bat的文件中): 当我运行myprogram.exe(这是一个简单的控制台应用程序)时,它要求我输入一些字符串。当我将一个字符串传递给它(input\u到\u myprogram)时,它会要求我再输入一个字符串(另一个\u input\u到\u myprogram)。此后,myprogram.exe将终止,因此mybatch.bat中的所有其他命令都是简单的shell命令(不是myprogram.exe的输入,因为它已经终止)。 我可以使用另一个文件来

有一个例子(比如在一个名为
mybatch.bat
的文件中):

当我运行
myprogram.exe
(这是一个简单的控制台应用程序)时,它要求我输入一些字符串。当我将一个字符串传递给它(
input\u到\u myprogram
)时,它会要求我再输入一个字符串(
另一个\u input\u到\u myprogram
)。此后,
myprogram.exe
将终止,因此
mybatch.bat
中的所有其他命令都是简单的shell命令(不是
myprogram.exe
的输入,因为它已经终止)。
我可以使用另一个文件来执行相同的操作,方法是将对
myprogram.exe的调用替换为
myprogram.exe
,并将其替换为
myprogram\u input.txt

input_to_myprogram
another_input_to_myprogram
但我只能使用一个文件来执行此操作(
mybatch.bat
)。
那么这是可能的还是不可能的?

谢谢。

您可以使用
echo
将所需字符串定向到myprogram.exe:

@echo off
(echo input_to_myprogram & echo another_input_to_myprogram) | myprogram.exe
another_program.exe
@echo off
(echo input_to_myprogram & echo another_input_to_myprogram) | myprogram.exe
another_program.exe