• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Accept Prompt in batch file

idroga

Junior Member
Hi,

I am trying to automate the execution of a program (.exe) using a batch file. When the file runs I get a prompt to press Enter which I cannot do in the batch file.

My code is:

@echo off
start "D:\Update" update.exe
sleep 60
echo.
sleep 300
echo.


I read in a forum that echo. would do the same as press enter but it doen't seem to work.

Any help would be appreciated.
Thank you.
 
I read in a forum that echo. would do the same as press enter but it doen't seem to work.

echo. prints a blank line / moves you down a line.

if you add a "pause" it will ask you press any key.

control goes to the "sleep" program then comes back to the batch file, so if you want the "sleep" program to automatically press enter you'll have to figure out how to do it inside the "sleep" command itself (possibly by adding another parameter like "sleep 30 /quiet" or disassembling and recompiling the exe) I think
 
Um, "start" spawns a new console. If the program that you are trying to automate is not a console program (i.e., GUI) or if it's spawned in a different console, there is nothing you can do from a batch file, period.

So if it's a console program and if you get rid of that start, then you can do something like the following to simulate a single [ENTER] keystroke.

Code:
echo. | example.exe

Or, for a more complex set of inputs, you can use

Code:
example.exe < simulated_input.txt

This is the same standard piping and stdin/stdout redirection that you also see on *nix systems.

Finally, if you ever need a batch file to wait for a spawned program to finish running, "start /wait" is far better than inserting arbitrary sleeps.
 
Back
Top