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?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Hans Mulder  
View profile  
 More options Nov 12 2012, 11:36 am
Newsgroups: comp.lang.python
From: Hans Mulder <han...@xs4all.nl>
Date: Mon, 12 Nov 2012 17:35:43 +0100
Local: Mon, Nov 12 2012 11:35 am
Subject: Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?
On 12/11/12 16:36:58, jkn wrote:

> slight followup ...

> I have made some progress; for now I'm using subprocess.communicate to
> read the output from the first subprocess, then writing it into the
> secodn subprocess. This way I at least get to see what is
> happening ...

> The reason 'we' weren't seeing any output from the second call (the
> 'xargs') is that as mentioned I had simplified this. The actual shell
> command was more like (in python-speak):

> "xargs -I {} sh -c \"test -f %s/{} && md5sum %s/{}\"" % (mydir, mydir)

> ie. I am running md5sum on each tar-file entry which passes the 'is
> this a file' test.

> My next problem; how to translate the command-string clause

>     "test -f %s/{} && md5sum %s/{}" # ...

> into s parameter to subprocss.Popen(). I think it's the command
> chaining '&&' which is tripping me up...

It is not really necessary to translate the '&&': you can
just write:

    "test -f '%s/{}' && md5sum '%s/{}'" % (mydir, mydir)

, and xargs will pass that to the shell, and then the shell
will interpret the '&&' for you: you have shell=False in your
subprocess.Popen call, but the arguments to xargs are -I {}
sh -c "....", and this means that xargs ends up invoking the
shell (after replacing the {} with the name of a file).

Alternatively, you could translate it as:

    "if [ -f '%s/{}' ]; then md5sum '%s/{}'; fi" % (mydir, mydir)

; that might make the intent clearer to whoever gets to
maintain your code.

Hope this helps,

-- HansM


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.