[Python-checkins] CVS: python/dist/src/Lib popen2.py,1.9,1.10
Fredrik Lundh
python-dev@python.org
Sun, 9 Jul 2000 10:59:34 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv4740/Lib
Modified Files:
popen2.py
Log Message:
- added popen.popen2/popen3/popen4 support for
windows.
- added optional mode argument to popen2/popen3
for unix; if the second argument is an integer,
it's assumed to be the buffer size.
- changed nt.popen2/popen3/popen4 return values
to match the popen2 module (stdout first, not
stdin).
Index: popen2.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/popen2.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** popen2.py 2000/02/04 15:10:34 1.9
--- popen2.py 2000/07/09 17:59:31 1.10
***************
*** 90,118 ****
return self.sts
! def popen2(cmd, bufsize=-1):
! """Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
! specified, it sets the buffer size for the I/O pipes. The file objects
! (child_stdout, child_stdin) are returned."""
! _cleanup()
! inst = Popen3(cmd, 0, bufsize)
! return inst.fromchild, inst.tochild
! def popen3(cmd, bufsize=-1):
! """Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
! specified, it sets the buffer size for the I/O pipes. The file objects
! (child_stdout, child_stdin, child_stderr) are returned."""
! _cleanup()
! inst = Popen3(cmd, 1, bufsize)
! return inst.fromchild, inst.tochild, inst.childerr
def _test():
teststr = "abc\n"
print "testing popen2..."
r, w = popen2('cat')
w.write(teststr)
w.close()
assert r.read() == teststr
print "testing popen3..."
! r, w, e = popen3(['cat'])
w.write(teststr)
w.close()
--- 90,142 ----
return self.sts
! try:
! from os import popen2
! except NameError:
! def popen2(cmd, mode='t', bufsize=-1):
! """Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
! specified, it sets the buffer size for the I/O pipes. The file objects
! (child_stdout, child_stdin) are returned."""
! if type(mode) is type(0) and bufsize == -1:
! bufsize = mode
! mode = 't'
! assert mode in ('t', 'b')
! _cleanup()
! inst = Popen3(cmd, 0, bufsize)
! return inst.fromchild, inst.tochild
! try:
! from os import popen3
! except NameError:
! def popen3(cmd, mode='t', bufsize=-1):
! """Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
! specified, it sets the buffer size for the I/O pipes. The file objects
! (child_stdout, child_stdin, child_stderr) are returned."""
! if type(mode) is type(0) and bufsize == -1:
! bufsize = mode
! mode = 't'
! assert mode in ('t', 'b')
! _cleanup()
! inst = Popen3(cmd, 1, bufsize)
! return inst.fromchild, inst.tochild, inst.childerr
+ try:
+ from os import popen4
+ except NameError:
+ pass # not on unix
+
def _test():
teststr = "abc\n"
print "testing popen2..."
r, w = popen2('cat')
+ print r, w
w.write(teststr)
w.close()
assert r.read() == teststr
print "testing popen3..."
! try:
! r, w, e = popen3(['cat'])
! except:
! r, w, e = popen3('cat')
! print r, w, e
w.write(teststr)
w.close()