Getting output from executed command that is not STDIN

Discussion in 'Python' started by Sami Viitanen, Aug 7, 2003.

  1. Hello,

    I'm using os.popen and read for reading command input to string but the
    string doesn't contain the same output that running the command manually or
    with os.system contains.

    with os.system:
    cvs server: Diffing //Project1
    File //Project1/testiware.txt is new; current revision 3.13
    File //Project1/what_is_version_control.txt is new; current revision 3.3
    cvs server: Diffing //Project1/Dir1
    File //Project1/Dir1/seltest.c is new; current revision 1.4
    File //Project1/Dir1/testi.c is new; current revision 1.2

    with os.popen and read:
    File //Project1/testiware.txt is new; current revision 3.13
    File //Project1/what_is_version_control.txt is new; current revision 3.3
    File //Project1/Dir1/seltest.c is new; current revision 1.4
    File //Project1/Dir1/testi.c is new; current revision 1.2

    ---
    Script doesn't read those "cvs server: Diffing" lines
    ---
    Sami Viitanen, Aug 7, 2003
    #1
    1. Advertising

  2. Sami Viitanen wrote:

    > I'm using os.popen and read for reading command input to string but the
    > string doesn't contain the same output that running the command manually or
    > with os.system contains.
    >
    > with os.system:
    > cvs server: Diffing //Project1
    > File //Project1/testiware.txt is new; current revision 3.13
    > File //Project1/what_is_version_control.txt is new; current revision 3.3
    > cvs server: Diffing //Project1/Dir1
    > File //Project1/Dir1/seltest.c is new; current revision 1.4
    > File //Project1/Dir1/testi.c is new; current revision 1.2
    >
    > with os.popen and read:
    > File //Project1/testiware.txt is new; current revision 3.13
    > File //Project1/what_is_version_control.txt is new; current revision 3.3
    > File //Project1/Dir1/seltest.c is new; current revision 1.4
    > File //Project1/Dir1/testi.c is new; current revision 1.2
    >
    > ---
    > Script doesn't read those "cvs server: Diffing" lines
    > ---


    looks like the program prints some output to stderr, and some to stdout.
    possible solutions:

    1) if your shell supports it, add "2>&1" to the end of the command line,
    to send all stderr output to stdout. random google link:
    http://www.zeitfenster.de/bash/Bash-Prog-Intro-HOWTO-3.html

    2) use os.popen4 to get a file handle representing both streams. see:
    http://www.python.org/doc/current/lib/os-newstreams.html#os-newstreams

    </F>

    <!-- (the eff-bot guide to) the python standard library (redux):
    http://effbot.org/zone/librarybook-index.htm
    -->
    Fredrik Lundh, Aug 7, 2003
    #2
    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. Johnathan Doe

    peek at stdin, flush stdin

    Johnathan Doe, May 15, 2004, in forum: C Programming
    Replies:
    5
    Views:
    24,808
    Chatoyer
    May 17, 2013
  2. Charlie Zender

    Reading stdin once confuses second stdin read

    Charlie Zender, Jun 19, 2004, in forum: C Programming
    Replies:
    6
    Views:
    762
    Dan Pop
    Jun 21, 2004
  3. Ben
    Replies:
    2
    Views:
    1,318
    jacob navia
    Aug 29, 2009
  4. Replies:
    2
    Views:
    716
  5. Terry Cooper
    Replies:
    7
    Views:
    417
    Janos Sebok
    Jun 9, 2009
Loading...

Share This Page