[wpkg-users] cmd exit code always 0
Rainer Meier
r.meier at wpkg.org
Wed Jun 24 18:40:10 CEST 2009
Hi Marc,
Marc Hennes wrote:
> I really love Windows ... calling exit without /b did the trick.
Sometimes I hate it ;-)
It seems that Windows XP is behaving somehow strange. I ought to remember that I
had a discussion with Tomasz once about the usage of /b. I was using /b and he
told me not to do so. It looks like on Vista and Windows 7 using the /b option
returns the correct exit code when a cmd script is run from cscript. However on
XP I would consider this to be a bug.
Just be careful. If you use exit without /b from a sub-script (called using the
"call <script>" method) then exit will not only exit the sub-script but
terminate the whole cmd process. Here you have to use exit /b in order to return
to the calling script. So the correct and portable way is probably that all
sub-scripts have to exit using exit /b in order to prevent early termination and
at the end of the main script you need to use exit without the /b parameter.
Unfortunately I really hate this because you never know if your script is the
"topmost" one - it might have been called by another one which you don't want to
terminate immediately.
So be aware...
> Thanks a lot Rainer
You're welcome. I just finished verifying it using a custom .js script and
calling your cmd script:
Using the /b parameter inside script.cmd:
C:\temp>cscript /NoLogo execute.js
Executing command: script.cmd
Exit Code: 0
Now without the /b switch:
C:\temp>cscript /NoLogo execute.js
Executing command: script.cmd
Exit Code: 2
And the same on Windows Vista:
Using /b:
C:\Temp>cscript /NoLogo execute.js
Executing command: script.cmd
Exit Code: 2
Without the /b switch:
C:\Temp>cscript /NoLogo execute.js
Executing command: script.cmd
Exit Code: 2
Crazy huh?
br,
Rainer
More information about the wpkg-users
mailing list