running a CMD as child is variable due to delay for Find 0=success and 1=fail but its always one step behind so all the errorlevels are “wrong”
Using || condition will certainly help with such odd behaviour
here the errorlevel is Unaffected by sumatraPDF running as a child the file does not exist but SumatraPDF exits cleanly so no error raised.
I agree with your observation
CONCLUSION: there is no errorcode when started interactively (as you already checked!), but there is an errorcode when started by a child CMD
.
SumatraPDF only sets command line error code when used as a command-line app for printing
not as a GUI app that does not report to the parent any failures whilst running in graphics mode. It’s any child process running SumatraPDF as a grandchild that returns its child failure errorlevels UNLESS SumatraPDF is invoked as a console app
You need to use the console to test if the file exists prior to launching a non console app.
It is exactly the same for any non console app like notepad. It does not matter if the file exists or not the errorlevel prior to a gui app invocation is the one that is kept in console memory. Notepad does not even raise an error on failing to console print, it is the execute via cmd that reports successful print of nothing.