diff options
author | Guido van Rossum <guido@python.org> | 1997-09-29 04:04:39 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-09-29 04:04:39 (GMT) |
commit | da286666b24e31a6ec16964963aaa3a83bcad751 (patch) | |
tree | 0882d035263a14d66a6b735c1d2d6d82aad1134c /Lib/popen2.py | |
parent | 54e2091ba25c449c0b591d92d40ddcb2a9cb153e (diff) | |
download | cpython-da286666b24e31a6ec16964963aaa3a83bcad751.zip cpython-da286666b24e31a6ec16964963aaa3a83bcad751.tar.gz cpython-da286666b24e31a6ec16964963aaa3a83bcad751.tar.bz2 |
Add optional bufsize argument to various calls so we can make the
os.fdopen() calls unbuffered. I presume that it's enough if we can
make all three of them (for stdin, stdout, and stderr) unbuffered and
don't need to specify different buffer sizes per file -- that would
complicate the interface more than I care for.
Diffstat (limited to 'Lib/popen2.py')
-rw-r--r-- | Lib/popen2.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/popen2.py b/Lib/popen2.py index b5defbc..d62f6a9 100644 --- a/Lib/popen2.py +++ b/Lib/popen2.py @@ -11,7 +11,7 @@ def _cleanup(): inst.poll() class Popen3: - def __init__(self, cmd, capturestderr=0): + def __init__(self, cmd, capturestderr=0, bufsize=-1): if type(cmd) == type(''): cmd = ['/bin/sh', '-c', cmd] p2cread, p2cwrite = os.pipe() @@ -41,12 +41,12 @@ class Popen3: # Shouldn't come here, I guess os._exit(1) os.close(p2cread) - self.tochild = os.fdopen(p2cwrite, 'w') + self.tochild = os.fdopen(p2cwrite, 'w', bufsize) os.close(c2pwrite) - self.fromchild = os.fdopen(c2pread, 'r') + self.fromchild = os.fdopen(c2pread, 'r', bufsize) if capturestderr: os.close(errin) - self.childerr = os.fdopen(errout, 'r') + self.childerr = os.fdopen(errout, 'r', bufsize) else: self.childerr = None self.sts = -1 # Child not completed yet @@ -68,14 +68,14 @@ class Popen3: _active.remove(self) return self.sts -def popen2(cmd): +def popen2(cmd, bufsize=-1): _cleanup() - inst = Popen3(cmd, 0) + inst = Popen3(cmd, 0, bufsize) return inst.fromchild, inst.tochild -def popen3(cmd): +def popen3(cmd, bufsize=-1): _cleanup() - inst = Popen3(cmd, 1) + inst = Popen3(cmd, 1, bufsize) return inst.fromchild, inst.tochild, inst.childerr def _test(): |