subprocess confusion

Michael Hoffman at mh391.invalid
Mon Apr 16 20:26:19 CEST 2007

Tim Arnold wrote:

> If 'machine' value is different than the current machine name, I want to 
> remsh the command to that machine, but obviously I misunderstood the 
> preexec_fn arg.

I don't think the return value of preexec_fn is used for anything. You 
can use to do things like set process group IDs in the child. For your 
use, everything needs to be args.

If you are using Python 2.5, and log is a file, you want:

from __future__ import with_statement

with log:
     if machine != socket.gethostname():
         command = "/bin/remsh %s %s" % (machine, command)

     subprocess.check_call(command, shell=True, env=env,
                           stderr=subprocess.STDOUT, stdout=log)

The semantics are slightly different, since log will always close this 
way, while in the other example, you have left it open if there is an 
Michael Hoffman

More information about the Python-list mailing list