pexpect and inconsistent exit codes

H

Heikki Toivonen

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@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@ubuntu:~/python_virtualenvs/fabexp$ python dep.py
cmd= true
child exitstatus= 1
child signalstatus= None
child status= 256
(fabexp)heikki@ubuntu:~/python_virtualenvs/fabexp$ python dep.py
cmd= true
child exitstatus= 0
child signalstatus= None
child status= 0
(fabexp)heikki@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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top