how to pass input to .exe in batch file?

2019-01-18 04:55发布

问题:

I have a .exe which requires 3 integers as input. For example:

myCode.exe < input.txt

In input.txt:

2
3
8

Now I want to put the command in a batch file. how can I write the batch file? (Here I want to pass 3 fixed integers in the batch file)

THANKS!

回答1:

This may also work:

(
echo 2
echo 3
echo 8
) | mycode.exe


回答2:

try this:

run.bat:

myCode.exe %1 %2 %3

call example:

run.bat 111 222 333

and with file:

run.bat < input.txt



回答3:

Here is a batch one-liner that will create the file for you and supply it as an input to the myCode.exe:

echo 2 3 8 > output & myCode.exe output

Otherwise, you'll probably need to modify your program to read the arguments directly from command line.

It's possible to redirect the program standard input/output/error streams to or from a file, but I think there is no way to redirect a command line contents to a standard input stream. Take a look at this page for details on batch redirection.



回答4:

try type input.txt | myCode.exe