os.popen does not seem to catch stdout

zane.selvans at gmail.com zane.selvans at gmail.com
Wed Nov 7 08:58:12 EST 2007


Hi there,

I've been banging my head against this for a day, and I can't take it
anymore.  It's probably a stupid error, but I don't see where.

I'm trying to use Python to call an external program, and then catch
and process the output of that program.  Seems simple enough.  The
command I'm trying to run, in the test, is:

"/Users/zane/svn/stress/satstress/satstress -r1.561e+06 -a5 -s45000 -
e0 -R6.709e+08 -g1.31472 -m1.8987e+27 -Q57100.1 -n0.333355 -Y9.29881e
+09 -k1e+22 -Z1.19173 -z-6.293e-05 -V0.309434 -v-2.903e-05 -W1.81305 -
w-0.00418645 -U0.474847 -u-0.00276624 -C /tmp/18_tmp.gen -b 60"

When I run it at my zsh prompt, I get the expected output.

If I let ss_cmd equal the above string within ipython (or the standard
python interactive interpreter):

ss_outlines = os.popen(ss_cmd).readlines()

ss_outlines contains the same output I saw when I ran the command at
my zsh prompt, one line per list element, as expected.

However, when I try doing the same thing from within a program, it
fails.  ss_outlines is an empty list.

I've tried using subprocess.Popen(), and subprocess.call(), and
subprocess.check_call(), and all have yielded similar results.  I did
find, however, that the return value python is getting from the
program I'm calling is different from what I get at the command line
(I get 0, python gets -11).

Does this ring a bell for anyone?

I'm using Python 2.5.1 on a Mac running OS X 10.5.




More information about the Python-list mailing list