Comment 15 for bug 1343657

Revision history for this message
Nathan Kinder (nkinder) wrote :

@slicknik
If you are referring to the usage of subprocess.PIPE for stderr/stdout, that will work fine with 'shell=False' as demonstrated by this sample program (create a /tmp/foo.txt with some content first):

-------------------------------------------------------------------------------------------
import os
import subprocess

command = '/usr/bin/cat /tmp/foo.txt'
backup_process = subprocess.Popen(['/usr/bin/cat', '/tmp/foo.txt'], shell=False,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE,
                                  preexec_fn=os.setsid)

print '%s' % backup_process.stdout.read()
-------------------------------------------------------------------------------------------

Are you piping the output of one command to another in the command that is passed into subprocess.Popen() in BackupRunner? If so, you can also do that like this:

-------------------------------------------------------------------------------------------
import os
import subprocess

command = '/usr/bin/cat /tmp/foo.txt'
backup_process = subprocess.Popen(['/usr/bin/cat', '/tmp/foo.txt'], shell=False,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE,
                                  preexec_fn=os.setsid)

grep_process = subprocess.Popen(['/usr/bin/grep', 'blah'], shell=False,
                                stdin=backup_process.stdout,
                                stdout=subprocess.PIPE)

print '%s' % grep_process.stdout.read()
-------------------------------------------------------------------------------------------