hep needed with pipes (popen4)

Gerhard =?unknown-8bit?Q?H=E4ring?= gh_pythonlist at gmx.de
Fri Feb 22 17:34:55 EST 2002


Le 22/02/02 ? 16:38, Darcy Kahle écrivit:
> I need some help with pipes in python 2.1.
> 
> I am running a comand using os.popen4().  The command produces output until
> the user hits control-C, at which time, it prints a summary, and exits.  I
> want to send that character down the pipe to it without the user doing so
> (control-c kills the script, by default).  I tried sending "\x003", which to
> the best of my knowledge, is the hex code for it, but it didn't work.

AFAIK you need to send the process a signal.  Using the signal module
and os.kill the code you need might look not entirely unlike this:

import signal, os

def sig_handler(signum, frame):
    global child_pid
    os.kill(signal.SIGINT, child_pid)

# open child process and store pid in global variable child_pid

signal.signal(signal.SIGINT, sig_handler)
while 1:
    pass
    # whatever

Gerhard
-- 
This sig powered by Python!
Außentemperatur in München: 5.8 °C      Wind: 5.9 m/s




More information about the Python-list mailing list