mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
#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
This commit is contained in:
parent
7e7a3ec901
commit
8b9020458a
5 changed files with 109 additions and 42 deletions
15
Lib/os.py
15
Lib/os.py
|
|
@ -666,8 +666,9 @@ if _exists("fork"):
|
|||
|
||||
import subprocess
|
||||
PIPE = subprocess.PIPE
|
||||
p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
|
||||
stdin=PIPE, stdout=PIPE, close_fds=True)
|
||||
p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring),
|
||||
bufsize=bufsize, stdin=PIPE, stdout=PIPE,
|
||||
close_fds=True)
|
||||
return p.stdin, p.stdout
|
||||
__all__.append("popen2")
|
||||
|
||||
|
|
@ -685,9 +686,9 @@ if _exists("fork"):
|
|||
|
||||
import subprocess
|
||||
PIPE = subprocess.PIPE
|
||||
p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
|
||||
stdin=PIPE, stdout=PIPE, stderr=PIPE,
|
||||
close_fds=True)
|
||||
p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring),
|
||||
bufsize=bufsize, stdin=PIPE, stdout=PIPE,
|
||||
stderr=PIPE, close_fds=True)
|
||||
return p.stdin, p.stdout, p.stderr
|
||||
__all__.append("popen3")
|
||||
|
||||
|
|
@ -705,8 +706,8 @@ if _exists("fork"):
|
|||
|
||||
import subprocess
|
||||
PIPE = subprocess.PIPE
|
||||
p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
|
||||
stdin=PIPE, stdout=PIPE,
|
||||
p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring),
|
||||
bufsize=bufsize, stdin=PIPE, stdout=PIPE,
|
||||
stderr=subprocess.STDOUT, close_fds=True)
|
||||
return p.stdin, p.stdout
|
||||
__all__.append("popen4")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue