Tuesday, May 15, 2007

Exit code from gobject spawned processes

[Python] Do you spawn a process using gobject's spawn_async() and want to find out what's the exit code? First, you have to add a callback to child_watch_add() function, which will be called when the process exits. This callback has this signature:

def callback(pid, condition, user_data)

Condition is the exit status information, but soon you will find out that it does not match the exit code. The reason is that it has both the exit code and the exit signal encoded in this variable. So, to find out each one, you have to do the following:

exitCode = (condition >> 8) & 0xFF
exitSignal = condition & 0xFF

Really really hard to find this information on the web to be able to check the exit code and do the appropriate action. I hope this helps you.
Post a Comment