pexpect and inconsistent exit values

Heikki Toivonen hjtoi-better-remove-when_replying at comcast.net
Mon Dec 15 13:01:46 EST 2008


I don't seem to be able to figure out how to get the exit values of
commands executed with pexpect reliably. Here's first with regular shell:

heikki at ubuntu:~$ true; echo $?
0

Let's try with pexpect. Below is the program:

---CLIP---
import sys, pexpect

cmd = "true"

print 'cmd=', cmd

child = pexpect.spawn(cmd, logfile=sys.stdout)
child.close()
print 'child exitstatus=', child.exitstatus
print 'child signalstatus=', child.signalstatus
print 'child status=', child.status
---CLIP---

The output:

(fabexp)heikki at ubuntu:~/python_virtualenvs/fabexp$ python dep.py
cmd= true
child exitstatus= 1
child signalstatus= None
child status= 256
(fabexp)heikki at ubuntu:~/python_virtualenvs/fabexp$ python dep.py
cmd= true
child exitstatus= 0
child signalstatus= None
child status= 0
(fabexp)heikki at ubuntu:~/python_virtualenvs/fabexp$ python dep.py
cmd= true
child exitstatus= None
child signalstatus= 1
child status= 1

I have tried various other commands, and I just can't seem to be able to
get reliable exit codes from commands I execute. Any ideas what is going on?

-- 
  Heikki Toivonen - http://heikkitoivonen.net



More information about the Python-list mailing list