Having .exe console program how do i start it up (the part that i know) and subsequently input prompts that come up(the part that i don't know; required input should be string, and if it matters there should be 3: first 5 then 0 then y) using batch file. The program itself starts up, then does its thing for around 10 seconds then it waits for input. Thanks
Asked
Active
Viewed 42 times
0
-
What kind of console EXE is it? Do you have source code? Do you know how it acquires input? – mojo Dec 21 '18 at 15:46
1 Answers
0
It greatly depends on how the console program accepts/reads input. It is possible to pipe in a text file with the responses you want, but not all programs will read them from stdin.
Suppose you create a file, responses.txt
:
3
5
0
y
Then, you pipe it to your console program, confirm_rocket_launch.exe
, using the stdin redirection operator, <
(less than):
X:\secret_dir> confirm_rocket_launch.exe <responses.txt
If you only had a single line of input to send it, you could skip the file and just use ECHO
and a pipe:
X:\secret_dir> ECHO y | confirm_rocket_launch.exe
That would do about all you can hope for from cmd.

mojo
- 4,050
- 17
- 24
-
Tried that, got the same error as before :\. TypeError: unicode() argument 2 must be string, not None – Dec 21 '18 at 15:42
-
-
If the exe is merely reading one character from stdin for each "input," your file might only need to contain `350y` all on one line. – mojo Dec 21 '18 at 15:48
-
Thought it might be that, but nope. Also tried all text encoding formats and still nothing. Been trying to figure this stuff for the past 4h and it's driving me mad. The thing is that i've got bunch of precompiled exe programs that are simple windows console applications; and i have to open like 15 of then and input arguments for each of them individualy. So i figured why not ease my way out of it by using some simple bat commands. As said before, opening the executables isn't the problem, the problem is in argument input. :C Perhaps simpler solution exists, and if so i'd gladly hear it. – Dec 21 '18 at 15:57
-
You might consider using [SendKeys](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys?view=netframework-4.7.2) from [PowerShell](https://stackoverflow.com/questions/17849522/how-to-perform-keystroke-inside-powershell). It's a little hack-y, but if you spawn the console exe in a different window with a specific title, you can find the window and send keystrokes to it. – mojo Dec 21 '18 at 16:02
-
AutoIt is another means of this kind of automation, but that might be too much overhead. – mojo Dec 21 '18 at 16:02
-