I've not had to write much batch file code in the past and I'm trying to understand why someone else's code has failed by writing a test batch file. My code:
:DoUntil
type p.txt >> log.txt
if %ERRORLEVEL% EQU 0 goto DoUntil
ECHO %ERRORLEVEL%
p.txt is an existing text file with a simple character string as is log.txt.
I then run this twice to get the error:
The process cannot access the file because it is being used by another process.
As you'd expect. Now I expected ERRORLEVEL to be set and a value returned by the echo, so what am I doing wrong please in ordered to get this echo'd as I expected? (it never hits the echo)
Or is there anywhere I can get a list of "type"s possible return value? I've found Googling on this subject quite frustrating due to how commonly used all the terms are! I read a few other questions on here which helped me correct one problem with my sample code but not the fundamental.
Edit:
Jeb's answer below was perfect in answering my query but I'm failing to take it forward. The problem code we have is like:
:DoUntil
type p.txt >> log.txt
if ERRORLEVEL 1 goto DoUntil
So the code is trying to say "if type fails, retry until it works". Are we saying by not having the "|| rem" clause+empty statement at the end of the type that the if statement is essentially doing nothing?