I've noticed some very strange behaviour when trying to write text to a file without having the trailing new line. There is code everywhere which looks like that:
echo|set /p=foo > foo.txt
It works great but my build system fails on that because when I evaluate %ERRORLEVEL% I get a 1 after the call:
echo %ERRORLEVEL%
echo |set /p=foo>foo.txt
echo %ERRORLEVEL%
returns
D:\>echo 0
0
D:\>echo | set /p=foo 1>foo.txt
D:\>echo 1
1
Is this a known behaviour? Is set
getting picky because there is no variable to set?
Note: The echoed code of echo |set /p=foo>foo.txt
is actually echo | set /p=foo 1>foo.txt
set /p
will set errorlevel to 1 because no input is given, whether you use a variable or not.