Reputation: 38255
In a Windows batch file, myScript.bat runs otherScript.bat, and in otherScript.bat, there's a pause in first line.
How can I send a keystroke thast skips the pause in myScript.bat? So my script won't need to take any extract keystroke and won't be blocked by the pause.
Upvotes: 54
Views: 28286
Reputation: 82257
I would recommend < NUL
instead of echo( |
@echo OFF
@echo Calling otherScript.bat...
set var=One
< NUL call otherScript.bat
@echo Done. var=%var%
@echo off
pause
echo Hello World
set var=two
The main difference is, otherscript runs in the same cmd.exe instance, but echo. | call ...
will run in a child cmd.exe.
A child instance has the problem, that otherscript can modify environment variables, but the changes are lost after the return
Upvotes: 2
Reputation: 29786
One way would be to use the echo
command to do the keystroke for you.
For example:
@echo OFF
@echo Calling otherScript.bat...
@echo | call otherScript.bat
@echo Done.
pause
@echo Hello World
Stefan's solution is more flexible and allows you to control when to pause or not, but this solution will work if you're not able to revise otherScript.bat for some reason.
Upvotes: 81
Reputation: 17018
You could modify otherScript.bat so that it accepts an optional parameter, telling it to skip the pause command like this:
if "%1"=="nopause" goto start
pause
:start
Upvotes: 22