You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
patch to subprocess docs to better explain Popen's 'args' argument #51009
From what I've seen on several c.l.p threads, some people have a tough
time figuring the correct 'args' argument to subprocess.Popen's
constructor. In an effort to cut down on such discussions in the future,
I've written the attached docs patch to better explain the subject.
I'm not an rst/Sphinx guru and thus was unable to actually test the
patch, so there might be some (hopefully minor) formatting errors.
The note starts out "Do not (do x) unless you're not (doing y)". This is confusing. I believe this means "If you are (doing y), you may (do x)". If so, please write it so. If not, please write what you do mean.
After thinking about it, "Only (do x) if you are (doing y)" might be a better rewrite. Or "You may (do x) only if you are (doing y)"
Change "be mindful of escaping" to the more direct "escape". Perhaps give a list of possible special characters.
I agree that this seems a bit verbose for reference documentation. Perhaps there should be a separate PyWiki entry or HowTo doc. That could, for instance, list the special characters for various shells if they are not all the same.
The raw_input() doesn't provide anything. I'd just drop that and pass the string directly to shlex.split.
"Do not put an argument-taking option together with its argument as a single item in the *args* list"
-- Something like "Argument-taking options should not be grouped with their arguments in the *args* list." may be a cleaner read, and avoids the big scary "do not".
"Because that is incorrect"
-- Maybe something like "shlex.split would suggest the following" instead?
cvrebert commented on Feb 2, 2010
cvrebertmannequin
MannequinAuthor
More actions
Gonna have to disagree about the raw_input(), because the escaping involved would complicate the example and could be distracting/confusing.
Rest of Brian's suggestions taken into account.
I still think this is much too verbose. The second note looks redundant with the first one and the third one.
Remember, the notes you are adding may be useful, but they'll also make reading the whole page more tedious.
cvrebert commented on Feb 2, 2010
cvrebertmannequin
MannequinAuthor
More actions
Well, the same basic example is used for cohesiveness, but the issue/pitfall being highlighted in each note is distinct. But you have a point about shlex being pointed out twice, so here's a version with that redundancy excised.
I'm happy to delete the two sentences about quoting.
As for -c, you are so right that it is cryptic. In the new version of the patch I've changed the sentence to be as precise as possible, but I'm not at all convinced that it is less confusing. This is why I think the API should be changed.
cvrebert commented on Feb 2, 2010
cvrebertmannequin
MannequinAuthor
More actions
This version takes Murray's most recent draft, applies some minor tweaks from my prior patch, and has the "python -c" etc. changed to "echo '$MONEY'" so the sh -c comment is completely unambiguous (and it's a simpler example generally).
Whether the subprocess.Popen() call should be demonstrated in the code snippet remains an open issue.
The change to echo is an excellent improvement. You forgot to change 'python' to 'echo' in the following paragraph, though. You are also correct about /bin/sh vs sh, my bad. And I was even looking at the source code when I wrote that...
As recommended by eric.smith on bpo-7950, I'd like to suggest further extending the documentation to include a security warning about (quite easily) possible code injection bugs when using the shell=True parameter (similar to other places in the documentation).
Activity
cvrebert commentedon Aug 22, 2009
From what I've seen on several c.l.p threads, some people have a tough
time figuring the correct 'args' argument to subprocess.Popen's
constructor. In an effort to cut down on such discussions in the future,
I've written the attached docs patch to better explain the subject.
I'm not an rst/Sphinx guru and thus was unable to actually test the
patch, so there might be some (hopefully minor) formatting errors.
benjaminp commentedon Sep 16, 2009
We are trying to cut down on the number of "warning" directives in the
docs; I think a "note" directive would be appropriate for yours.
cvrebert commentedon Oct 4, 2009
Ok, changed to "note" directives instead of "warning"s. Anything else
that keeps this from being applied?
pitrou commentedon Feb 1, 2010
This is a particularly verbose patch for the information it is trying to convey.
terryjreedy commentedon Feb 1, 2010
The note starts out "Do not (do x) unless you're not (doing y)". This is confusing. I believe this means "If you are (doing y), you may (do x)". If so, please write it so. If not, please write what you do mean.
After thinking about it, "Only (do x) if you are (doing y)" might be a better rewrite. Or "You may (do x) only if you are (doing y)"
Change "be mindful of escaping" to the more direct "escape". Perhaps give a list of possible special characters.
I agree that this seems a bit verbose for reference documentation. Perhaps there should be a separate PyWiki entry or HowTo doc. That could, for instance, list the special characters for various shells if they are not all the same.
terryjreedy commentedon Feb 1, 2010
PS. I only looked at the style of the patch. Once that is clearer, someone who knows more than me needs to review it for content correctness.
cvrebert commentedon Feb 2, 2010
Working on a more concise new draft...
cvrebert commentedon Feb 2, 2010
Okay; new, hopefully better, draft. Feedback?
briancurtin commentedon Feb 2, 2010
The raw_input() doesn't provide anything. I'd just drop that and pass the string directly to shlex.split.
"Do not put an argument-taking option together with its argument as a single item in the *args* list"
-- Something like "Argument-taking options should not be grouped with their arguments in the *args* list." may be a cleaner read, and avoids the big scary "do not".
"Because that is incorrect"
-- Maybe something like "shlex.split would suggest the following" instead?
cvrebert commentedon Feb 2, 2010
Gonna have to disagree about the raw_input(), because the escaping involved would complicate the example and could be distracting/confusing.
Rest of Brian's suggestions taken into account.
pitrou commentedon Feb 2, 2010
I still think this is much too verbose. The second note looks redundant with the first one and the third one.
Remember, the notes you are adding may be useful, but they'll also make reading the whole page more tedious.
cvrebert commentedon Feb 2, 2010
Well, the same basic example is used for cohesiveness, but the issue/pitfall being highlighted in each note is distinct. But you have a point about shlex being pointed out twice, so here's a version with that redundancy excised.
8 remaining items
bitdancer commentedon Feb 2, 2010
I'm happy to delete the two sentences about quoting.
As for -c, you are so right that it is cryptic. In the new version of the patch I've changed the sentence to be as precise as possible, but I'm not at all convinced that it is less confusing. This is why I think the API should be changed.
cvrebert commentedon Feb 2, 2010
This version takes Murray's most recent draft, applies some minor tweaks from my prior patch, and has the "python -c" etc. changed to "echo '$MONEY'" so the sh -c comment is completely unambiguous (and it's a simpler example generally).
Whether the subprocess.Popen() call should be demonstrated in the code snippet remains an open issue.
bitdancer commentedon Feb 2, 2010
The change to echo is an excellent improvement. You forgot to change 'python' to 'echo' in the following paragraph, though. You are also correct about /bin/sh vs sh, my bad. And I was even looking at the source code when I wrote that...
ericvsmith commentedon Feb 2, 2010
Now you need to put the import of subprocess back in!
Otherwise it looks good to me.
cvrebert commentedon Feb 4, 2010
Okay, now if this could just get dev review...
ericvsmith commentedon Feb 4, 2010
I think this is an improvement to the existing docs, and should be committed.
ncoghlan commentedon Feb 4, 2010
Committed for 2.7 as r77959.
Still needs to be merged to the other branches.
ericvsmith commentedon Feb 4, 2010
When merging to py3k, don't forget to modify the print statement to be a function.
bitdancer commentedon Feb 4, 2010
Merged as part of r77961 (2.6), r77962 (py3k), and r77963 (3.1). Print fixed for py3.
cvrebert commentedon Feb 4, 2010
Thanks to all for the copious feedback & suggestions, and R. David Murray for his superior docs writing skills!
cvrebert commentedon Feb 5, 2010
One problem with the 3.x versions: the raw_input() should be input().
bitdancer commentedon Feb 5, 2010
Thanks for catching that. Fixed r77987 r77988.
christophneuroth commentedon Feb 18, 2010
As recommended by eric.smith on bpo-7950, I'd like to suggest further extending the documentation to include a security warning about (quite easily) possible code injection bugs when using the shell=True parameter (similar to other places in the documentation).