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.68.248.34 with SMTP id yj2mr10118089pbc.2.1352881374928;
        Wed, 14 Nov 2012 00:22:54 -0800 (PST)
Path: s9ni10644pbb.0!nntp.google.com!news.glorb.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!news.xs4all.nl!not-for-mail
Date: Wed, 14 Nov 2012 09:22:52 +0100
From: Hans Mulder <han...@xs4all.nl>
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0
MIME-Version: 1.0
Newsgroups: comp.lang.python
Subject: Re: how to simulate tar filename substitution across piped subprocess.Popen()
 calls?
References: <da975275-d4ce-4a01-892b-8a1e1274b611@b19g2000vbt.googlegroups.com> <509c588a$0$6904$e4fe514c@news2.news.xs4all.nl> <5b39febc-fbb9-4d8e-b331-0401e78d2b7f@m13g2000vbd.googlegroups.com> <fdc89c1f-d0da-4fd3-8576-3cd7c94cba89@k21g2000vbj.googlegroups.com> <50a12560$0$6972$e4fe514c@news2.news.xs4all.nl> <b4f250bb-94da-4ce2-9b30-d40a41adb570@k6g2000vbr.googlegroups.com> <50a1402d$0$6947$e4fe514c@news2.news.xs4all.nl> <k7uehf$8iq$1@r03.glglgl.gl>
In-Reply-To: <k7uehf$8iq$1@r03.glglgl.gl>
Lines: 35
Message-ID: <50a354dd$0$6982$e4fe514c@news2.news.xs4all.nl>
NNTP-Posting-Host: 80.126.109.81
X-Trace: 1352881373 news2.news.xs4all.nl 6982 80.126.109.81:63483
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

On 13/11/12 22:36:47, Thomas Rachel wrote:
> Am 12.11.2012 19:30 schrieb Hans Mulder:
> 
>> This will break if there are spaces in the file name, or other
>> characters meaningful to the shell.  If you change if to
>>
>>          xargsproc.append("test -f '%s/{}'&&  md5sum '%s/{}'"
>>                               % (mydir, mydir))
>>
>> , then it will only break if there are single quotes in the file name.
> 
> And if you do mydir_q = mydir.replace("'", "'\\''") and use mydir_q, you
> should be safe...

The problem isn't single quotes in mydir, but single quotes in the
files names that 'tar' generates and 'xargs' consumes.  In the shell
script, these names go directly from tar to xargs via a pipe.  If the
OP wants to do your replace, his script would have to read the output
of tar and do the replace before passing the filenames down a second
pipe to xargs.

However, once he does that, it's simpler to cut out xargs and invoke
"sh" directly.  Or even cut out "sh" and "test" and instead use
os.path.isfile and then call md5sum directly.  And once he does that,
he no longer needs to worry about single quotes.

The OP has said, he's going to d all that.  One step at a time.
That sounds like a sensible plan to me.


Hope this helps,

-- HansM