473,287 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

os.popen does not seem to catch stdout

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.

Nov 7 '07 #1
4 4865
On Nov 7, 7:58 am, zane.selv...@gmail.com wrote:
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.
I think when you use subprocess.Popen, you need to do something set
the shell to True to get it to behave like running from a command
prompt:

subprocess.Popen('some command', shell=True)

See http://docs.python.org/lib/node529.html for more details.

You'll also find a fairly interesting thread on this topic here:

http://mail.python.org/pipermail/chi...er/000141.html
http://mail.python.org/pipermail/pyt...er/347508.html

This seems to be a recipe on it:

http://aspn.activestate.com/ASPN/Coo.../Recipe/440554

Mike

Nov 7 '07 #2
On Nov 7, 11:31 am, kyoso...@gmail.com wrote:
On Nov 7, 7:58 am, zane.selv...@gmail.com wrote:
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.

I think when you use subprocess.Popen, you need to do something set
the shell to True to get it to behave like running from a command
prompt:

subprocess.Popen('some command', shell=True)

Seehttp://docs.python.org/lib/node529.htmlfor more details.

You'll also find a fairly interesting thread on this topic here:

http://mail.python.org/pipermail/chi...er/347508.html

This seems to be a recipe on it:

http://aspn.activestate.com/ASPN/Coo.../Recipe/440554

Mike

That's right, and I think you also want to put the whole command in a
list or tuple, one item for each arg. I don't know why though.

-Greg

Nov 7 '07 #3
On Nov 7, 12:17 pm, "gregpin...@gmail.com" <gregpin...@gmail.com>
wrote:
On Nov 7, 11:31 am, kyoso...@gmail.com wrote:
On Nov 7, 7:58 am, zane.selv...@gmail.com wrote:
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.
I think when you use subprocess.Popen, you need to do something set
the shell to True to get it to behave like running from a command
prompt:
subprocess.Popen('some command', shell=True)
Seehttp://docs.python.org/lib/node529.htmlformore details.
You'll also find a fairly interesting thread on this topic here:
http://mail.python.org/pipermail/chi...000141.htmlhtt...
This seems to be a recipe on it:
http://aspn.activestate.com/ASPN/Coo.../Recipe/440554
Mike

That's right, and I think you also want to put the whole command in a
list or tuple, one item for each arg. I don't know why though.

-Greg
I've never had to put the command into a list or tuple...but you're
welcome to try it that way.

Mike

Nov 7 '07 #4
On Wed, 07 Nov 2007 18:35:51 +0000, kyosohma wrote:
I've never had to put the command into a list or tuple...but you're
welcome to try it that way.
You don't *have* to but if you do the module takes care of quoting the
arguments if necessary.

Ciao,
Marc 'BlackJack' Rintsch
Nov 7 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tung Wai Yip | last post by:
I've build the following utility. It works so far but I want to make sure I'm doing the right thing. I am running Python 2.3 on windows 2000. def execute(cmd): """ execute cmd in sub-process,...
5
by: damacy | last post by:
hello, everyone. i am trying to write a program which executes SQL commands stored in ..sql files. i wrote a function called psql() whose contents look like the following. .......
9
by: Clodoaldo Pinto Neto | last post by:
Output from the shell: $ set | grep IFS IFS=$' \t\n' Output from subprocess.Popen(): "IFS=' \t\n" Both outputs for comparison:
2
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import...
3
by: Jesse | last post by:
Hi all, I have a problem using wget and Popen. I hope someone can help. -- Problem -- I want to use the command: wget -nv -O "dir/cpan.txt" "http://search.cpan.org" and capture all it's...
8
by: dmoore | last post by:
Hi folks, I've seen the following issue come up in multiple posts to this mailing list: I have a python program that spawns a child process with popen or popen2 or popen3 or popen2.popen2...
12
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with...
8
by: clyfish | last post by:
In cmd, I can use find like this. C:\>netstat -an | find "445" TCP 0.0.0.0:445 0.0.0.0:0 LISTENING UDP 0.0.0.0:445 *:* C:\> And os.system is OK....
5
by: thedsadude | last post by:
Hello, I'm launching a script as follows: <code> p = subprocess.Popen() p.wait() </code> If p.py writes to sys.stdout, then it is shown on the console.
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.