Jump to content

Getting Exit Code From Console Using 'Run'?

Recommended Posts

I've been updating some scripts that run console applications, adding the new StdoutRead function to display results in AutoIt's GUI rather than leaving the DOS box on screen.

In some of these earlier scripts, I've used RunWait and checked its return value to know the console app's exit code. Something like this:

SplashTextOn("Working", $splash_txt)
$err = RunWait(@ComSpec & " /c " & $consoleapp_exe, "", @SW_SHOW)

If $err Then
    MsgBox(4096, "Failed", "return value: " & $err)
    MsgBox(4096, "Complete", "No errors!")

When I update these scripts to use StdoutRead, I have to switch from RunWait to Run so I can monitor and display the output channel. That's no problem; I'm able to do this and read and display the progress just fine.

Here's my question: since Run returns a process ID instead of an exit code like RunWait, I can't check for errors the same way I used to. Is the console app's "exit code" still available somewhere? Short of parsing the text from Stdout (ugh!) what's the best way to tell whether the console app has exited successfully or with an error?

I'd like to get the value represented by $err using Run instead of RunWait. How do I do dat?

Link to post
Share on other sites

This is a post from a thread on this subject, Celeri used DLLCall to call Windows API functions before and after reading with StdoutRead to get the exit code.

It's agreed that this is something that should be obtainable in AutoIt. I had initially suggested that StdoutRead return the exit code in @extended which would be do-able fairly quickly, then the discussion switched to a developer thread where it was recommended that there would be a GetProcessExitCode function et al. but currently only calls to Run with the console pipe ($stdXXX_child) parameter supplied are being tracked for an exit code, so there'd have to be an infrastructure change, blah blah, and we're supposed to be under a feature freeze and pushing for a stable AutoIt release, so in short (heh) nothing has been done toward providing this...

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...