Bob
Bob

Reputation: 4980

windows batch - ECHO is changing the %ERRORLEVEL%

I have the following .bat snippet

echo about to start echoing, Errorlevel=%Errorlevel%

echo. >> ../time.txt

echo Just echod a new line into time.txt, Errorlevel=%Errorlevel%

echo | set/p=start=%time%, >> ../time.txt    

echo about to start with emake, Errorlevel=%ERRORLEVEL%

The output is:

about to start echoing, Errorlevel=0
Just echod a new line into time.txt, Errorlevel=0
about to start with emake, Errorlevel=1

Why is the line echo | set/p=start=%time%, >> ../time.txt changing the %ERRORLVEL%?

Upvotes: 2

Views: 1668

Answers (1)

dbenham
dbenham

Reputation: 130889

That lines sets ERRORLEVEL to 1 because SET /P fails (sets ERRORLEVEL to 1) whenever it fails to set a value, and your set/p=start=%time%, will never set a value. Everything after the first = is considered to be the prompt, so there is no variable, and the command will always "fail".

I have no idea what you are attempting to do with that line, so I can't give you a solution. But one thing you should be aware of - SET /P is useless for setting variables if used within a pipe.

Upvotes: 3

Related Questions