Posts Tagged ‘Batch’

I see your errorlevel and raise you a process exit code

December 7, 2012

Have you ever written a batch file that is more of a “application” than a script? Of course you made sure ERRORLEVEL is set correctly so when your batch file is a part of a larger script, IF ERRORLEVEL error checking can be used. What could go wrong?

For some crazy reason, cmd.exe does not use the expected logic when you use the && and/or || syntax. I assume part of the problem is because the batch file is executed by cmd.exe itself and there is no child process and no real process exit code.

Fixing this requires some hacky workarounds and is generally a big pain in the ass.


The bastard love child of BAT and WSH

November 4, 2009

The (default) PATHEXT environment variable contains .vbs/.js/.wsf but wscript.exe is usually set as the default windows scripting engine host, so running scripts in a terminal is a big pain. What if we could put the WSH script inside a batch file so we don’t have to prefix every call with cscript //nologo ?