how to simulate tar filename substitution across piped subprocess.Popen() calls?

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Tue Nov 13 13:52:30 EST 2012


Am 09.11.2012 02:12 schrieb Hans Mulder:

> That's what 'xargs' will do for you.  All you need to do, is invoke
> xargs with arguments containing '{}'.  I.e., something like:
>
> cmd1 = ['tar', '-czvf', 'myfile.tgz', '-c', mydir, 'mysubdir']
> first_process = subprocess.Popen(cmd1, stdout=subprocess.PIPE)
>
> cmd2 = ['xargs', '-I', '{}', 'sh', '-c', "test -f %s/'{}'" % mydir]
> second_process = subprocess.Popen(cmd2, stdin=first_process.stdout)

After launching second_process, it might be useful to 
firstprocess.stdout.close(). If you fail to do so, your process is a 
second reader which might break things apart.

At least, I once hat issues with it; I currently cannot recapitulate 
what these were nor how they could arise; maybe there was just the open 
file descriptor which annoyed me.


Thomas



More information about the Python-list mailing list