Rahul J
Rahul J

Reputation: 199

Why I am getting "Echo is on" when trying to print a variable in batch

I tring to excute a simple batch file scripts :

echo %1
set var = %1
echo %var%

When I am running it in XP, it is giving me expected output, but When I am running it in Vista or windows 7, I am getting "Echo is On" when trying to print (echo) value.

Below is the output of program :

G:\2012>abc.bat 1

G:\2012>echo 1
1

G:\2012>set var = 1

G:\2012>echo
ECHO is on.

G:\2012>

Upvotes: 17

Views: 25633

Answers (2)

Michael
Michael

Reputation: 88

I had this error when I tried to do an echo without any value and redirect to a file using Python. Looks to be a hidden troubleshooting feature in the echo command.

Upvotes: 0

C.J.
C.J.

Reputation: 16081

Get rid of the spaces in your set expression. There can and should be no spaces on either side of the equal sign (=)

set var=%1

BTW: I usually start all my batch files with @echo off, and end them with @echo on too, so I can avoid mixing code with the output of the batch file. It just makes your batch file output a little nicer and cleaner.

Upvotes: 22

Related Questions