View Single Post
  #2  
Old September 18th 04, 11:37 PM
Franc Zabkar
external usenet poster
 
Posts: n/a
Default

On Fri, 17 Sep 2004 23:46:59 -0400, Robertson Pimentel
put finger to keyboard and composed:

I'm writing a script that captures the return code from a command EXE file
and acts according to the code.

I have a variable called intErr that captures the exit code from the
command:
intErr = objShell.Run(" %comspec% /C mycommand" , 9, True)
The code works well in Win2K and XP, but it doesn't work in 98.
Windows 98 seems to always return 0 (succesful execution).

When I go in 98 and run command.com /Z and execute this manually, I can see
the correct return code in this format:
Return code (ERRORLEVEL): 2

What I've done so far:
1. I tried checking for the OS version and running %comspec% /Z in case of
98 but this does not work. (It opens a command window, does not execute my
probgram and exits with 0).
2. I tried writing a batch file that can be invoked from the script that
contains the following:
@Echo Off
%comspec% /Z
mycommand


@echo off
%comspec% /z /k mycommand
exit

This doesn't work either. For some reason you can't use batch with
command.com /Z
3. I've tried concatenating the command to the shell. Doesn't work.
4. I tried modifying the config.sys with the following line:
SHELL=C:\COMMAND.COM C:\ /E:4096 /P /Z
This doesn't make all my command lines to behave like I want.

I think the problem is that 98 does not store the %errorlevel% environment
variable, so you have to use command.com /Z strictly to get this.

Any Ideas?


Execute mycommand and then test for the errorlevel using DOS's "if
errorlevel n" command.

From the online help for DOS:

================================================== ================
IF ERRORLEVEL number
Specifies a true condition only if the previous program run by
COMMAND.COM returned an exit code equal to or greater than number.
================================================== ================

Here is a possible example:

@echo off
mycommand
set result=0
if errorlevel 1 set result=1
if errorlevel 2 set result=2
echo Errorlevel is %result%

You would probably get much better answers from the experts at
comp.os.msdos.misc or alt.msdos.batch.


- Franc Zabkar
--
Please remove one 's' from my address when replying by email.