mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
The command can now either be a string (as before) or a list of
arguments for execvp (for those who don't want the shell's argument parsing).
This commit is contained in:
parent
963b871e86
commit
6dd4868681
1 changed files with 4 additions and 3 deletions
|
@ -12,7 +12,8 @@ def _cleanup():
|
||||||
|
|
||||||
class Popen3:
|
class Popen3:
|
||||||
def __init__(self, cmd, capturestderr=0):
|
def __init__(self, cmd, capturestderr=0):
|
||||||
cmd = ['/bin/sh', '-c', cmd]
|
if type(cmd) == type(''):
|
||||||
|
cmd = ['/bin/sh', '-c', cmd]
|
||||||
p2cread, p2cwrite = os.pipe()
|
p2cread, p2cwrite = os.pipe()
|
||||||
c2pread, c2pwrite = os.pipe()
|
c2pread, c2pwrite = os.pipe()
|
||||||
if capturestderr:
|
if capturestderr:
|
||||||
|
@ -34,7 +35,7 @@ class Popen3:
|
||||||
os.close(i)
|
os.close(i)
|
||||||
except: pass
|
except: pass
|
||||||
try:
|
try:
|
||||||
os.execv(cmd[0], cmd)
|
os.execvp(cmd[0], cmd)
|
||||||
finally:
|
finally:
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
# Shouldn't come here, I guess
|
# Shouldn't come here, I guess
|
||||||
|
@ -85,7 +86,7 @@ def _test():
|
||||||
w.close()
|
w.close()
|
||||||
assert r.read() == teststr
|
assert r.read() == teststr
|
||||||
print "testing popen3..."
|
print "testing popen3..."
|
||||||
r, w, e = popen3('cat')
|
r, w, e = popen3(['cat'])
|
||||||
w.write(teststr)
|
w.write(teststr)
|
||||||
w.close()
|
w.close()
|
||||||
assert r.read() == teststr
|
assert r.read() == teststr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue