473,386 Members | 1,720 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,386 software developers and data experts.

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

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...&group_id=5470

Any suggestions would be greatly appreciated!
Jul 18 '05 #1
2 7169
David Carroll <vm*****@hotmail.com> pisze:
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).

--
Jarek Zgoda
Registered Linux User #-1
http://www.zgoda.biz/ JID:ja***@jabberpl.org http://zgoda.jogger.pl/
Jul 18 '05 #2
David Carroll wrote:
#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...&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

Jul 18 '05 #3

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

Similar topics

2
by: Jerry Sievers | last post by:
Hello. Maybe I'm just out of practice, maybe not. Suppose we run a command using system() and this command writes to the stderr stream. If I remember correctly, this is normally written to the...
2
by: leroybt.rm | last post by:
I don't understand why this does not work: <FILE1> test1.py #Import Packages import string # data=0 data=data+1
20
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've...
13
by: Larry Menard | last post by:
Test code: $dbconn = odbc_connect($dbname, $username, $password); $path = "C:\Temp\myJar.jar"; $statement = "CALL SQLJ.INSTALL_JAR('file://$path', 'myJarId')"; $result = odbc_exec($dbconn,...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 393 open (+15) / 3315 closed (+17) / 3708 total (+32) Bugs : 908 open (+22) / 5975 closed (+49) / 6883 total (+71) RFE : 223 open...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
2
by: Matimus | last post by:
On Apr 11, 2:32 am, Evan <xdi...@gmail.comwrote: Do you want a custom shell that does whatever you want? Or do you want an interactive python shell that has some custom commands? For the first...
9
by: Krumble Bunk | last post by:
Hi all, I am trying my hands at writing a shell for unix. A very rubbish shell, but nonetheless, I come to a point where I am confused. I would like to have something like shellstop xyz ...
0
by: Gabriel Genellina | last post by:
En Thu, 25 Sep 2008 09:49:31 -0300, Almar Klein <almar.klein@gmail.com> escribió: Use subprocess.PIPE Usually the tricky part is to figure out exactly whether there is more input or not. With...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.