__version__ = "Revision: 1.15 "
-# Id: subproc.py,v 1.15 1998/12/14 20:53:16 klm Exp
+# Id: subproc.py,v 1.15 1998/12/14 20:53:16 klm Exp
# Originally by ken manheimer, ken.manheimer@nist.gov, jan 1995.
# Prior art: Initially based python code examples demonstrating usage of pipes
got0 = self.readPendingChars(n)
got = got + got0
n = n - len(got0)
- return got
+ return got
def readPendingChars(self, max=None):
"""Read all currently pending subprocess output as a single string."""
return self.readbuf.readPendingChars(max)
got = ""
if self.buf:
- if (max > 0) and (len(self.buf) > max):
- got = self.buf[0:max]
- self.buf = self.buf[max:]
- else:
- got, self.buf = self.buf, ''
- return got
+ if (max > 0) and (len(self.buf) > max):
+ got = self.buf[0:max]
+ self.buf = self.buf[max:]
+ else:
+ got, self.buf = self.buf, ''
+ return got
if self.eof:
- return ''
+ return ''
sel = select.select([self.fd], [], [self.fd], 0)
if sel[2]:
c.write(s)
c.seek(0)
r = c.read()
- show = " start:\t %s\n end:\t %s\n" % (`s`, `r`)
+ show = " start:\t %s\n end:\t %s\n" % (repr(s), repr(r))
if r != s:
raise IOError("String distorted:\n%s" % show)
line = string.splitfields(line, ':')
it[string.strip(line[0])] = (
string.strip(string.join(line[1:])))
-
+
def getreply(self):
"""Consume next response from ph, returning list of lines or string
err."""
print("\t...yep, it failed.")
print('\tWrite, then read, two newline-teriminated lines, using readline:')
p.write('first full line written\n'); p.write('second.\n')
- print(`p.readline()`)
- print(`p.readline()`)
+ print(repr(p.readline()))
+ print(repr(p.readline()))
print('\tThree lines, last sans newline, read using combination:')
p.write('first\n'); p.write('second\n'); p.write('third, (no cr)')
print('\tFirst line via readline:')
- print(`p.readline()`)
+ print(repr(p.readline()))
print('\tRest via readPendingChars:')
print(p.readPendingChars())
print("\tStopping then continuing subprocess (verbose):")