Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion how to simulate tar filename substitution across piped subprocess.Popen() calls?

Received: by 10.224.223.14 with SMTP id ii14mr7878082qab.3.1352724923444;
        Mon, 12 Nov 2012 04:55:23 -0800 (PST)
MIME-Version: 1.0
Received: by 10.236.88.236 with SMTP id a72mr2223358yhf.20.1352724923414; Mon,
 12 Nov 2012 04:55:23 -0800 (PST)
Path: gf5ni18188417qab.0!nntp.google.com!c7no20993120qap.0!postnews.google.com!m13g2000vbd.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Mon, 12 Nov 2012 04:55:23 -0800 (PST)
Complaints-To: groups-abuse@google.com
Injection-Info: m13g2000vbd.googlegroups.com; posting-host=62.7.92.68; posting-account=xy4V0QkAAAAoGgkMsSsv6bfFPHkQXvOY
NNTP-Posting-Host: 62.7.92.68
References: <da975275-d4ce-4a01-892b-8a1e1274b611@b19g2000vbt.googlegroups.com>
 <509c588a$0$6904$e4fe514c@news2.news.xs4all.nl>
User-Agent: G2/1.0
X-HTTP-Via: 1.1 INTERNETSERVER
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0,gzip(gfe)
Message-ID: <5b39febc-fbb9-4d8e-b331-0401e78d2b7f@m13g2000vbd.googlegroups.com>
Subject: Re: how to simulate tar filename substitution across piped
 subprocess.Popen() calls?
From: jkn <jkn...@nicorp.f9.co.uk>
Injection-Date: Mon, 12 Nov 2012 12:55:23 +0000
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Hans
    thanks a lot for your reply:

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

Hmm - that's pretty much what I've been trying. I will have to
experiment a bit more and post the results in a bit more detail.

> > Apologies if I've made any howlers in this description - it's very
> > likely...
>

> I think the second '-c' argument to tar should have been a '-C'.

You are correct, thanks. Serves me right for typing the simplified
version in by hand. I actually use the equivalent "--directory=3D..." in
the actual code.

> I'm not sure I understand what the second command is trying to
> achieve. =A0On my system, nothing happens, because tar writes the
> names of the files it is adding to stderr, so xargs receives no
> input at all. =A0If I send the stderr from tar to the stdin of
> xargs, then it still doesn't seem to do anything sensible.

That's interesting ... on my system, and all others that I know about,
the file list goes to stdout.

> Perhaps your real xargs command is more complicated and more
> sensible.

Yes, in fact the output from xargs is piped to a third process. But I
realise this doesn't alter the result of your experiment; the xargs
process should filter a subset of the files being fed to it.

I will experiment a bit more and hopefully post some results. Thanks
in the meantime...

    Regards
    Jon N