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

2

17

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>
Carilyn answered 8/9, 2012 at 7:0 Comment(1)
set var=%1 pause output:= C:\>set var= C:\Users\vpatel\Desktop>pause Press any key to continue . . . Does not asked for user inoutMalony
O
22

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.

Obtrusive answered 8/9, 2012 at 8:27 Comment(0)
P
0

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.

Phalangeal answered 14/9, 2022 at 21:4 Comment(3)
well described behaviour. See echo /?Circular
I typed that on Windows using Gitbash and Linux and the output is '/?' I was using the os.system command in my Python btw. This is the manual for the linux echo command. linux.die.net/man/1/echo There is no referance to ECHO ON or ECHO OFF in there. So it is therefor hidden. Now I'm sure it's documented somewhere on the web but it's far from obvious.Phalangeal
Well, the question isn't about git or linux, but tagged Windows, Windows-7, batch-file (which is the Windows command line interpreter) and dos (which is a common mistake and should be cmd, the Windows command line) Other languages may have a command with the same name, but don't expect it to behave identically.Circular

© 2022 - 2024 — McMap. All rights reserved.