how to pass input to .exe in batch file?
Solution 1
This may also work:
(
echo 2
echo 3
echo 8
) | mycode.exe
Solution 2
try this:
run.bat:
myCode.exe %1 %2 %3
call example:
run.bat 111 222 333
and with file:
run.bat < input.txt
Solution 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.
Related videos on Youtube
Helen
Updated on July 05, 2022Comments
-
Helen almost 2 years
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!
-
Helen over 10 yearsNow the code is in C# and is using Console.readLine() to get input. I may need to add newline between 2 and 3.
-
Vladimir Sinenko over 10 yearsTake a look here for embedding a newline constants in a batch file. You'll just probably need three echo statements on a line.
-
Helen over 10 yearsecho 9 && echo. && echo 19 && echo. $$ echo 2 > output | myCode.exe output i ll try if this works. Thanks Vladimir!
-
foxidrive over 10 yearsIt's standard practice to separate commands with an ampersand
command1 & command2
as a pipe will confuse newbies and teach them false practices. -
Vladimir Sinenko over 10 years@foxidrive, absolutely agreed. Edited the answer accordingly.
-
dbenham over 10 years+1, But based on way question is phrased, the OP may need the simpler
echo 1 2 3|mycode.exe
-
foxidrive over 10 years@dbenham I wondered about that and just edited the question - they were indeed on separate lines.
-
dbenham over 10 yearsThe OP wants to avoid a temporary file, and the code will not work with the name of the temp file passed as an argument; it must be used as redirected input.
-
Stephan over 5 years
cat
is not a nativecmd
command, but a unix command (the commandtype
does basically the same, but with fewer options).