How to? Save and then restore "Echo" status

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
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.
 
#3
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.)