When I CALL
one Windows .bat
file from another, can the called file tell whether ECHO
was ON
or OFF
in the caller?
When a .bat
file is entered, ECHO
is set to ON
(even if it was OFF
in the CALLER).
I want to preserve the caller's ECHO
status
in the called .bat
so I can control both (possibly a chain of more than two nested calls) from a single place.
I could pass a parameter or set my own environment variable but is there a better way?
EDIT Just to clarify what's needed: callee.cmd needs to do things with echo off only for the duration of its run. Upon returning to its caller, it must restore the echo state the caller had.
Please fill in the ?????s in the script below:
callee.cmd:
@rem save the echo state
@ ???? HOW???? ????
@ set "savedEchoState=??????"
@rem the following commands must not be echoed
@echo off
command1
command2
command3
@rem restore the previous echo state
echo %savedEchoState%
caller1.cmd:
@echo off
call callee.cmd
echo
caller2.cmd:
@echo on
call callee.cmd
echo
Required output:
caller1.cmd must print echo off
and caller2.cmd must print echo on
.
Can it be done without creating any files on a disk?
@echo off
in batch files because echo is on at the interactive prompt. However, if we deliberately have echo on in a caller batch, and we call this batch file that starts with@echo off
, we would want to set echo back to on before we exit so that the caller keeps its echo-on status.