Re: pty.spawn directs stderr to stdout

Discussion in 'Python' started by Donn Cave, Apr 11, 2008.

  1. Donn Cave

    Donn Cave Guest

    In article <>,
    Wilbert Berendsen <> wrote:

    > Hi,
    >
    > using pty.spawn() it seems that stderr output of the spawned process is
    > directed to stdout. Is there a way to keep stderr separate and only direct
    > stdin and stdout to the pty?


    There is, of course.

    First, you have to decide where you want unit 2 ("stderr") to go, and
    then get the spawned process to redirect it there. If a disk file
    will do, then your question is just "how do I redirect error output
    to a disk file, in ___" (fill in the blank with language used to
    implement the spawned process - UNIX shell? Python? C?)

    More likely, you want the spawned process' error output to go wherever
    the parent's error output was going. This is a little trickier.

    Ideally, your spawned shell script can conveniently take a new
    parameter that identifies the new file descriptor unit number for
    error output. In this case, use fd2 = os.dup(2) to get a new
    duplicate, add a parameter like -e str(fd2), and in the spawned
    process, redirect from that unit - in UNIX shell, exec 2>&$fd2

    Or you could use an environment variable to identify the backup
    error unit, if the command line parameter option isn't available
    for some reason.

    Donn Cave,
     
    Donn Cave, Apr 11, 2008
    #1
    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. Derek Basch
    Replies:
    2
    Views:
    1,306
    Donn Cave
    Jan 21, 2005
  2. Ed Hames
    Replies:
    0
    Views:
    378
    Ed Hames
    Apr 16, 2008
  3. Edgardo Hames
    Replies:
    1
    Views:
    353
    Ed Hames
    May 6, 2008
  4. Najati Imam
    Replies:
    2
    Views:
    489
  5. Evan Driscoll
    Replies:
    0
    Views:
    216
    Evan Driscoll
    Oct 24, 2012
Loading...

Share This Page