If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
capturing external commands exit codes in Win98
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 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? |
#2
|
|||
|
|||
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. |
#3
|
|||
|
|||
Franc Zabkar wrote:
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 Thanks for your suggestion Frank. Tom at the scripting.vbscript group suggested me to use Win95Cmd.exe instead of the Win9x command.com. That version actually returns the error code from the external command allowing me to capture it in a vbscript variable. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Prodcut Codes for Win98 | DonnieBoy | Disk Drives | 1 | July 4th 04 07:02 PM |