summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorPhilip Jenvey <pjenvey@underboss.org>2009-09-29 19:18:11 (GMT)
committerPhilip Jenvey <pjenvey@underboss.org>2009-09-29 19:18:11 (GMT)
commit7865296ca3e6fb179860c899b3a3a198e6f317c1 (patch)
tree7b48927f5ff54972e19434e9cdb16c2d1bd8ac6d /Doc
parentb4b94ef437d997ad0619345243a112e744f52245 (diff)
downloadcpython-7865296ca3e6fb179860c899b3a3a198e6f317c1.zip
cpython-7865296ca3e6fb179860c899b3a3a198e6f317c1.tar.gz
cpython-7865296ca3e6fb179860c899b3a3a198e6f317c1.tar.bz2
Merged revisions 75143 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r75143 | philip.jenvey | 2009-09-29 12:10:15 -0700 (Tue, 29 Sep 2009) | 5 lines #5329: fix os.popen* regression from 2.5: don't execute commands as a sequence through the shell. also document the correct subprocess replacement for this case patch from Jean-Paul Calderone and Jani Hakala ........
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/subprocess.rst50
1 files changed, 30 insertions, 20 deletions
diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst
index 2bc8f74..c6bd07b 100644
--- a/Doc/library/subprocess.rst
+++ b/Doc/library/subprocess.rst
@@ -418,21 +418,21 @@ Replacing :func:`os.popen`, :func:`os.popen2`, :func:`os.popen3`
::
- pipe = os.popen(cmd, 'r', bufsize)
+ pipe = os.popen("cmd", 'r', bufsize)
==>
- pipe = Popen(cmd, shell=True, bufsize=bufsize, stdout=PIPE).stdout
+ pipe = Popen("cmd", shell=True, bufsize=bufsize, stdout=PIPE).stdout
::
- pipe = os.popen(cmd, 'w', bufsize)
+ pipe = os.popen("cmd", 'w', bufsize)
==>
- pipe = Popen(cmd, shell=True, bufsize=bufsize, stdin=PIPE).stdin
+ pipe = Popen("cmd", shell=True, bufsize=bufsize, stdin=PIPE).stdin
::
- (child_stdin, child_stdout) = os.popen2(cmd, mode, bufsize)
+ (child_stdin, child_stdout) = os.popen2("cmd", mode, bufsize)
==>
- p = Popen(cmd, shell=True, bufsize=bufsize,
+ p = Popen("cmd", shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE, close_fds=True)
(child_stdin, child_stdout) = (p.stdin, p.stdout)
@@ -440,9 +440,9 @@ Replacing :func:`os.popen`, :func:`os.popen2`, :func:`os.popen3`
(child_stdin,
child_stdout,
- child_stderr) = os.popen3(cmd, mode, bufsize)
+ child_stderr) = os.popen3("cmd", mode, bufsize)
==>
- p = Popen(cmd, shell=True, bufsize=bufsize,
+ p = Popen("cmd", shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
(child_stdin,
child_stdout,
@@ -450,21 +450,33 @@ Replacing :func:`os.popen`, :func:`os.popen2`, :func:`os.popen3`
::
- (child_stdin, child_stdout_and_stderr) = os.popen4(cmd, mode, bufsize)
+ (child_stdin, child_stdout_and_stderr) = os.popen4("cmd", mode,
+ bufsize)
==>
- p = Popen(cmd, shell=True, bufsize=bufsize,
+ p = Popen("cmd", shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
+On Unix, os.popen2, os.popen3 and os.popen4 also accept a sequence as
+the command to execute, in which case arguments will be passed
+directly to the program without shell intervention. This usage can be
+replaced as follows::
+
+ (child_stdin, child_stdout) = os.popen2(["/bin/ls", "-l"], mode,
+ bufsize)
+ ==>
+ p = Popen(["/bin/ls", "-l"], bufsize=bufsize, stdin=PIPE, stdout=PIPE)
+ (child_stdin, child_stdout) = (p.stdin, p.stdout)
+
Return code handling translates as follows::
- pipe = os.popen(cmd, 'w')
+ pipe = os.popen("cmd", 'w')
...
rc = pipe.close()
- if rc != None and rc % 256:
+ if rc != None and rc % 256:
print "There were some errors"
==>
- process = Popen(cmd, 'w', stdin=PIPE)
+ process = Popen("cmd", 'w', shell=True, stdin=PIPE)
...
process.stdin.close()
if process.wait() != 0:
@@ -474,11 +486,6 @@ Return code handling translates as follows::
Replacing functions from the :mod:`popen2` module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-.. note::
-
- If the cmd argument to popen2 functions is a string, the command is executed
- through /bin/sh. If it is a list, the command is directly executed.
-
::
(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode)
@@ -487,9 +494,12 @@ Replacing functions from the :mod:`popen2` module
stdin=PIPE, stdout=PIPE, close_fds=True)
(child_stdout, child_stdin) = (p.stdout, p.stdin)
-::
+On Unix, popen2 also accepts a sequence as the command to execute, in
+which case arguments will be passed directly to the program without
+shell intervention. This usage can be replaced as follows::
- (child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize, mode)
+ (child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize,
+ mode)
==>
p = Popen(["mycmd", "myarg"], bufsize=bufsize,
stdin=PIPE, stdout=PIPE, close_fds=True)