
Wscript.quit and ErrorLevel on 9x batch file
Yup, the Win 9x OS does not supply the Errorlevel (nor the OS, Hompage,
UserName ... environment variables). COMSPEC, PATH, PROMPT, CMDLINE,
windir, winbootdir and TEMP\TMP are all she wrote.
If you want to 'Echo' the errorlevel you can try something like this ...
for %%v in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %%v set EL=%%v
for %%v in (0 1 2 3 4 5 6 7 8 9) do if errorlevel 1%%v set EL=%%v
echo %EL%
Or for testing purposes, you can try the (undocumented) /Z switch of the
command processor, COMMAND.COM. It causes the errorlevel to be
displayed after any procedure that (re)set the errorlevel. Use it for
debugging from a command prompt something like this ...
%comspec% /z /k
Use the EXIT statement to close the secondary instance of the command
processor.
Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/
Quote:
> OK, I am so used to batching in NT/2000 I keep forgetting about
> Win9X behavior. I was doing this which works on NT/2000
> TESTS.BAT:
> Call cscript test.vbs
> Echo the exit code returned was %errorlevel%
> TEST.VBS:
> Option Explicit
> Wscript.Echo "We ran the script"
> wscript.Quit (44)
> On Win9x this does not work and the errorlevel returned is blank. I
> have to test specifically for the errorlevel and I cannot echo it
> for some reason, feel free to enlighten me or if anyone has
> different results please let me know :) This is using the same VBS
> file but the batch file is different.
> TESTS.BAT:
> call CScript test.vbs
> IF NOT ERRORLEVEL 1 GOTO DONE
> ECHO An error occurred with exit code 1 or higher.
> :DONE
> ECHO End of batch file.
> Do you guys have the same behaivor?
> > hmmm... Yes I am running it in Cscript :)
> > Well I am not able to test right now, but I will try it without the ()
> > around the exit code later today.
{the rest omitted}