Odd behaviour of ECHO

D

Den

Group:

I needed a command file that would save the ECHO state at the beginning of
the file and then restore the ECHO state at the end.

I came up with the following simple command line (written for command
prompt -- double the %'s for command file!):
for /f "tokens=3 delims=. " %s in ('echo') do set echostate=%s
... which I believe should set the environment variable "echostate" to
either "on" or "off", dependant on the current setting of ECHO.

However, under XP Pro it always sets the value to "on", regardless of the
actual current setting of ECHO.

So, to test, I changed the line to:
for /f "tokens=3 delims=. " %s in ('echo') do echo --%s--
... at the command line this always returns "--on--", regardless of the
actual current setting of ECHO (i.e. is consitent with the earlier example).

Further playing around (at the command prompt) shows that the ECHO command
yields "ECHO is off.", or "ECHO is on." depending on the state of ECHO,
*but*, ECHO|MORE always yields "ECHO is on." even when ECHO is set off.

I'm missing something here ... can someone explain?

Cheers

Den
 
M

Mark L. Ferguson

C:\Documents and Settings\Mark>echo off
echo > out.txt
for /f "tokens=3 delims=. " %s in ('type out.txt') do set echostate=%s
set echostate
echostate=off
 
D

Den

Mark

Yep - I agree that that works ... and indeed that this the solution that I'm
using. However, it is not as elegant as:
for /f "tokens=3 delims=. " %s in ('echo') do set echostate=%s
... which *should* work.

Any ideas *why* it isn't working, and if there is any relation to the
echo|more issue?

Cheers

D
 
M

Mark L. Ferguson

I would say that echo probably determines it's state by determining if stdout is piped, or not.

C:\Documents and Settings\Mark>echo off
echo > con
ECHO is off.
echo > con | more
ECHO is on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top