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

Discussion in 'Python' started by David Carroll, Sep 13, 2003.

  1. 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!
    David Carroll, Sep 13, 2003
    #1
    1. Advertising

  2. David Carroll

    Jarek Zgoda Guest

    David Carroll <> 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: http://zgoda.jogger.pl/
    Jarek Zgoda, Sep 13, 2003
    #2
    1. Advertising

  3. David Carroll

    Peter Otten Guest

    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=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
    Peter Otten, Sep 13, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. n.o.
    Replies:
    0
    Views:
    335
  2. Replies:
    2
    Views:
    305
  3. Replies:
    3
    Views:
    383
    John Roth
    Jul 29, 2005
  4. .rhavin grobert

    vector: Foo[5] == ((foo*)Foo) + 5 ?

    .rhavin grobert, Sep 23, 2008, in forum: C++
    Replies:
    4
    Views:
    390
    JaredGrubb
    Sep 24, 2008
  5. Replies:
    4
    Views:
    142
    Thomas 'PointedEars' Lahn
    Dec 23, 2007
Loading...

Share This Page