2

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%?

Bob
  • 4,576
  • 7
  • 39
  • 107
  • It's not `echo`; it's `set`command wrong syntax; use `echo | set/p start=%time%, >> ../time.txt` – JosefZ Jun 16 '16 at 16:25

1 Answers1

3

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.

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • I'm not trying to set anything. Rather, I use that construct - from a stack post - to be able to `echo` without newlining. – Bob Jun 16 '16 at 18:54
  • I fixed the %ERRORLEVEL% via `echo | set /p start=%time%, >> ../time.txt` and it still outputs on same line as I need it to. – Bob Jun 16 '16 at 18:59