commands.getstatusoutput("FOO") -- won't work for me

D

David Carroll

I'm at my wits end with this silly thing. I'm new to python, so please
excuse my impending ignorance ;). I am trying to execute a command, and
get the output back into a string variable. Here's what I think should
work from the docs I've read. The system I need to get this working on is
2000 professional, I'm posting this from my linux box, so please
don't look poorly upon me for the windows thing, it wasn't my choice.

import commands

#chop
status, output = commands.getstatusoutput("dir")
print "Output: ", output
print "Status: ", status
#chop

"""
returns:

C:\starNE>counter.py
Output: '{' is not recognized as an internal or external command,
operable program or batch file.
Status: 1

It returns that "'{' is not recogni..." with anything I pass as a command.
"""


os.system("dir")

works just fine, but I don't think I can capture the output, am I a victim
of a bug here?
Could it be related to this posting I googled?

http://sourceforge.net/tracker/?func=detail&atid=105470&aid=506100&group_id=5470

Any suggestions would be greatly appreciated!
 
J

Jarek Zgoda

David Carroll said:
I'm at my wits end with this silly thing. I'm new to python, so please
excuse my impending ignorance ;). I am trying to execute a command, and
get the output back into a string variable. Here's what I think should
work from the docs I've read. The system I need to get this working on is
2000 professional, I'm posting this from my linux box, so please
don't look poorly upon me for the windows thing, it wasn't my choice.

import commands
[...]

Any suggestions would be greatly appreciated!

Module commands works only on Unix systems, as you can read in Library
Reference (Chapter 8.: Unix specific services).
 
P

Peter Otten

David said:
#chop
status, output = commands.getstatusoutput("dir")
print "Output: ", output
print "Status: ", status
#chop

"""
returns:

C:\starNE>counter.py
Output: '{' is not recognized as an internal or external command,
operable program or batch file.
Status: 1
[snip]
Could it be related to this posting I googled?
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=506100&group_id=5470

Yes, the 2.3 commands module is still Unix-only.

Use os.popen("dir") directly instead or copy the suggested fix from sf into
your module (not commands.py) to roll your own version of
getstatusoutput().

Peter
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top