[Tutor] os.popen3 > subprocess.Popen but nohup.out won't go

Sander Sweers sander.sweers at gmail.com
Sat Apr 4 12:24:13 CEST 2009


2009/4/4 dave selby <dave6502 at googlemail.com>:
> os.popen3('nohup %s/core/kmotion_hkd2.py &> /dev/null &' % kmotion_dir)
>
> becomes ..
>
> subprocess.Popen('nohup %s/core/kmotion_hkd2.py &> /dev/null &' %
> kmotion_dir, shell=True)
>
> all is well except I now get
>
> nohup: appending output to `nohup.out'
>
> on the terminal which '&> /dev/null' used to ditch to /dev/null. I
> think this is because subprocess simulates the
> shell differently. Any idea how to ditch to /dev/null in subprocess ?

Subprocess by default does not store stdout and stderror. Try this:

proc = subprocess.Popen('nohup %s/core/kmotion_hkd2.py' % kmotion_dir,
shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE)

Now proc.communicate returns a tuple with (stdout, strderr). You can
also make stdout/stderr go to a file, below untested!

outfile = open('/tmp/myoutfile')
errfile = open('/tmp/myerrfile')

proc = subprocess.Popen('nohup %s/core/kmotion_hkd2.py' % kmotion_dir,
shell=True, stdout=outfile,stderr=errfile)

proc.communicate()

Greets
Sander


More information about the Tutor mailing list