How to pass input to .exe in a batch file?

I have a .exe that requires 3 integers. 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 a batch file? (Here I want to pass 3 fixed integers in a batch file)

THANKS!

+7
command batch-file
source share
3 answers

This may also work:

 ( echo 2 echo 3 echo 8 ) | mycode.exe 
+12
source share

try the following:

run.bat:

myCode.exe %1 %2 %3

Call example:

run.bat 111 222 333

and with the file:

run.bat < input.txt

+4
source share

Here is a single line batch file that will create the file for you and provide it as input to myCode.exe :

 echo 2 3 8 > output & myCode.exe output 

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

You can redirect standard input / output / error streams to or from a file, but I think there is no way to redirect the contents of the command line to standard input stream. Take a look at this page for details of batch redirection.

+1
source share

All Articles