How to? Save and then restore "Echo" status

May 24, 2010
855
0
Northlake, Il
I'm writing a batch file (as is typical) and there is an area code of that is not quite working the way I would like it to, so I'd like to "bracket" that area of code by "Echo On" and "Echo Off' statements to try to determine what is "going on". However, that area of code can also (potentially) make calls to a very-substantial but long-used and "proven" subroutine where I absolutely do not want echo to be "on". So, the "solution" to that problem is simple in principle: "Capture" the current echo state at the "top" of the subroutine and save it; turn echo "Off"; do my thing in the subroutine; and then restore "Echo" to its "original" state before exiting the subroutine, and I have code that does that and does, in fact, work but I consider it to be quite "ugly":
Code:
:Subroutine
   @Echo >!Z:\Temp\ExcludeLinesEchoStatus.%_PID.txt
   @Echo Off
   Echo This is just an Echo command to check whether the "Echo" command itself is echoed..
   @Echo %@Word[2,%@Line[Z:\Temp\ExcludeLinesEchoStatus.%_PID.txt,0]]
   @Del Z:\Temp\ExcludeLinesEchoStatus.%_PID.txt >NUL:
   @Return
This works and isn't quite as bad as it could be because Z:, as often mentioned, is a RAM disk; but then I don't consider having to write the current echo status to a file and then read it back in to be at all an "optimal" solution.

Is there another, "better" way?

- Dan

P. S. And thank you again, Frank for reminding me about the "@Word..." functions. This is a perfect example of when its use can really simplify things.
 
May 24, 2010
855
0
Northlake, Il
Yes, there is, Charles, and it shouldn't surprise me that that is the case since Rex seems to have thought of virtually everything!:) (While I suspected as much which why I asked the question in the first place, I really didn't have any clear idea of what "form" it would take - although an internal variable is eminently sensible in hindsight.)
 
Similar threads
Thread starter Title Forum Replies Date
I How to? Save and restore folder timestamps Support 22
J Utility to Save/Restore current screen Support 16
millardjk Save & restore font in IDE (10b68) Support 1
RChrismon How to? Changes to Options Don't Save Support 8
M Save the environment .. ;-) Support 2
R V19 - At startup, TCC save directory in the directory history list Support 2
T Fixed V18 debugger crashed on save button Support 1
SeoulBigChris Save Environment (Tabs) on Exit? Support 3
M How to? Save the session log from a batch file? Support 5
R Toolbar - save to .INI Support 4
A TCMD10 doesn't save options until restarted Support 10
E Save TCC configuration Support 1
TT's Help! Uninstalling TCC did not restore cmd.exe as Win10 default batch file processor. Support 4
I How to? Backup and restore timestamps of files? Support 3
I How to? Backup and restore file timestamps Support 13
WadeHatler Any way to restore the Text Based "Select File" Windows in TCC Support 2
CWBillow Backup / Restore of Take Command Settings Support 3
fpefpe How to? command echo in title line/bar Support 2
vefatica @EXECSTR clobbers @ECHO ON Support 2
L WAD ECHO. expansion of non-existent env-vars differs from CMD.exe Support 6
D Does TCC improve CMD's implementation of ECHO? Support 6
E My echo full file name to the clipboard fails now. Support 2
MickeyF how to ECHO in opposite colors? Support 12
Joe Caverly Echo message works without the space? Support 3
T Fixed Echo randomly activated in script Support 4
S How to? ^C echo Support 6
vefatica ECHO is very slow Support 9
J How to? Riddle: How to echo > into a file? Support 7
Alexander How to? how can I use Cyrillic characters in the Echo command? Support 8
jadaml Echo unicode characters from UTF-8 Batch files? Support 1
vefatica WAD DO, ECHO, and trailing whitespace Support 3
nickles WAD echo "%PROGRAMFILES(X86)%" Support 16
J Can you redirect output to printer device with echo? Support 1
T Set 1% then Echo 1% Support 9
M echo %@index[1234,.,-1] return -21 in new version Support 3
Roedy ECHO bug Support 4
T How do you echo lines with special characters to file? Support 4

Similar threads