Jump to content

Cmd Exit Codes with XP


Recommended Posts

Hi-

I'm having a problem trying to have AutoIT return the correct exit code from a batch program in Windows XP. Here is a sample of what I'm trying to do:

Test.cmd

@Echo off

Set ExitNumber=0

echo This is a test

echo Setting Exitnumber to 3

Set ExitNumber=3

Goto EoF

:EoF

echo New ExitNumber is: %ExitNumber%

Exit /b %ExitNumber%

Now if I call that bat file from AutoIt using the RunWait function all I get is 0, instead of what I expect which is 3.

$Results = RunWait(@ComSpec & " /C test.cmd, @scriptdir, @SW_Show)

MsgBox(0,"ExitCode", $Results)

If I run this code on Vista or Windows 7 it works fine.

Any help on this would be great :)

Thanks,

Andrew

Link to comment
Share on other sites

Don't use the '/b' in the exit parameter, it is pointless in this situation.

:: Previous batch code
EXIT %ExitNumber%

Also you could ditch the whole @COMSPEC business, and just run the target batch direct:

$R = RunWait("TEST.bat",@SCRIPTDIR)

Of course you will need the @COMSPEC macro if for some reason '.bat' or '.cmd' is not registered to cmd.exe in the shell of your system.

Worked! :)

I knew it was probably something simple. Weird, all the documentation I found said I needed to use the /b switch to send the exit code.

Thanks for your help.

Andrew

Link to comment
Share on other sites

Worked! :)

I knew it was probably something simple. Weird, all the documentation I found said I needed to use the /b switch to send the exit code.

Thanks for your help.

Andrew

The '/b' parameter of the exit command is only useful when calling one batch from another (ie at the batch level to give an exit code to the parent batch file) , or when you don't want the batch file to terminate your current instance of the command shell when it exits.

wtfpl-badge-1.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...