subprocess and PPID

Michele Petrazzo michele.petrazzo at
Thu Nov 6 08:48:52 CET 2008

Jorgen Grahn wrote:
> On Wed, 5 Nov 2008 08:19:34 -0800 (PST), saju.pillai at
> <saju.pillai at> wrote:
>> On Nov 5, 5:12 pm, Michele Petrazzo
>> <michele.petra... at> wrote:
>>> Hi all, I believe that this is a *nix question, but since I'm
>>> developing in python, I'm here.
>>> I have a code that execute into a "Popen" a command (ssh). I need
>>> that,
> What's 'a "Popen"'? Is it os.popen or one of its variants?

Popen is the default python Popen:

from subprocess import Popen, PIPE

cmd = "ssh -C -N -i keys/id_rsa_key -L remote:ip:local who at where"

cmd_p = Popen(cmd.split(), stdout=PIPE, stderr=PIPE)

> Do you read from it or write to it?  If you do both, you should use 
> something like the third-party module pexpect instead.

Nothing. I do only a tunnel

>> To reliably have the child exit when the parent exits, you would
>> have to poll for the parent from the child and do a exit when the
>> child detects that the parent has gone away.
> But in the special case where he's feeding data into "ssh somewhere 
> somecmd" or pulling data from it, a crash of the parent should make 
> "somecmd" exit because it sees EOF, and thus make the ssh process
> end. Sounds relatively risk-free -- but it depends on "somecmd".

Interesting. So, how I have to modify my code (if I can)? Add an stdin?

> /Jorgen


More information about the Python-list mailing list