I have a minimal batch script on my windows machine desktop which uses the
FC.exe tool to compare two text files also on my desktop.
My files to compare
file1.txt contains one character a
file2.txt contains one character b
My batch file
SET "result=success"
fc.exe "%USERPROFILE%\Desktop\file1.txt" "%USERPROFILE%\Desktop\file2.txt"
IF NOT ERRORLEVEL 0 SET "result=failed"
echo %result%
pause
I expect the var result to be failed (as file1 is different to file2),
however the output shows it is success
I have tried changing the only character b to a in file2.txt and
running the batch file again, but the output shows the result var is still
success
Furthermore, I can append the following
...
echo %ERRORLEVEL%
...
directly under the fc.exe cmd, and it prints 1 for the first test and 0 for
the second, this result should cause the IF loop to trigger but it does not.
What is the cause of this?
IF ERRORLEVEL X checks if errorlevel is equal or greater than X so IF NOT ERRORLEVEL 0 checks if the errorlevel is less than 0. Use conditional execution or IF %ERRORLEVEL% NEQ 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With