popen and i/o redirection question

Grant Edwards grant at nowhere.
Thu Mar 30 18:03:22 EST 2000


In article <8c099c$o3d$1 at info3.fnal.gov>, Charles G Waldman wrote:

>I am using the popen2 module to start an instance of "gdb".
>Then I send some gdb commands to set a few breakpoints and 
>start a program.

Hey, me too. (My gdb is running something that doesn't have
stdout and stderr, so I don't have the problem you mentioned.)

>Once the program starts, the standard output and standard error
>from that program come back to the top-level Python process
>through the same pipes as gdb's stdout and stderr.
>
>What I'd like to be able to do is to have the I/O to the debugging
>target on different pipes than the I/O to gdb itself, but I haven't
>been able to figure out quite how to do this.
>
>Does anybody have any suggestions?

You can use the "tty" gdb command to specify what terminal is
to be used for the running program.  I haven't tried this, but
my first suggestion would be: in your python program open up
the master device of a pty pair, and tell gdb to use the slave
device for the program being run.

For example:

In your python program open /dev/ptyb9 for reading.

Before you send the "run" command, send the command "tty /dev/ttyb9".

Now, when your program runs, stdout and stderr will be readable
via /dev/ptyb9.

(You need to pick a pseudo-terminal device pair that isn't
being used -- the naming conventions for pty device pairs on
your system may differ).

-- 
Grant Edwards                   grante             Yow!  LIFE is a
                                  at               never-ending INFORMERCIAL!
                               visi.com            



More information about the Python-list mailing list