return self.readPendingChars()
got = ''
while n:
- got = got + self.readPendingChars(n)
- n = n - len(got)
+ got0 = self.readPendingChars(n)
+ got = got + got0
+ n = n - len(got0)
return got
def readPendingChars(self, max=None):
"""Read all currently pending subprocess output as a single string."""
os.kill(self.pid, signal.SIGSTOP)
except os.error:
if verbose:
- print "Stop failed for '%s' - '%s'" % (self.cmd, sys.exc_value)
+ print("Stop failed for '%s' - '%s'" % (self.cmd, sys.exc_value))
return 0
- if verbose: print "Stopped '%s'" % self.cmd
+ if verbose: print("Stopped '%s'" % self.cmd)
return 'stopped'
def cont(self, verbose=0):
os.kill(self.pid, signal.SIGCONT)
except os.error:
if verbose:
- print ("Continue failed for '%s' - '%s'" %
- (self.cmd, sys.exc_value))
+ print(("Continue failed for '%s' - '%s'" %
+ (self.cmd, sys.exc_value)))
return 0
- if verbose: print "Continued '%s'" % self.cmd
+ if verbose: print("Continued '%s'" % self.cmd)
return 'continued'
def die(self):
# WNOHANG == 1 on sunos, presumably same elsewhere.
if os.waitpid(self.pid, os.WNOHANG):
if self.expire_noisily:
- print ("\n(%s subproc %d '%s' / %s)" %
+ print(("\n(%s subproc %d '%s' / %s)" %
(sig[0], self.pid, self.cmd,
- hex(id(self))[2:]))
+ hex(id(self))[2:])))
for i in self.pipefiles:
os.close(i)
self.pid = 0
#############################################################################
def test(p=0):
- print "\tOpening subprocess:"
+ print("\tOpening subprocess:")
p = Subprocess('cat', 1) # set to expire noisily...
- print p
- print "\tOpening bogus subprocess, should fail:"
+ print(p)
+ print("\tOpening bogus subprocess, should fail:")
try:
b = Subprocess('/', 1)
- print "\tOops! Null-named subprocess startup *succeeded*?!?"
+ print("\tOops! Null-named subprocess startup *succeeded*?!?")
except SubprocessError:
- print "\t...yep, it failed."
- print '\tWrite, then read, two newline-teriminated lines, using readline:'
+ 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 '\tThree lines, last sans newline, read using combination:'
+ print(`p.readline()`)
+ print(`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 '\tRest via readPendingChars:'
- print p.readPendingChars()
- print "\tStopping then continuing subprocess (verbose):"
+ print('\tFirst line via readline:')
+ print(`p.readline()`)
+ print('\tRest via readPendingChars:')
+ print(p.readPendingChars())
+ print("\tStopping then continuing subprocess (verbose):")
if not p.stop(1): # verbose stop
- print '\t** Stop seems to have failed!'
+ print('\t** Stop seems to have failed!')
else:
- print '\tWriting line while subprocess is paused...'
+ print('\tWriting line while subprocess is paused...')
p.write('written while subprocess paused\n')
- print '\tNonblocking read of paused subprocess (should be empty):'
- print p.readPendingChars()
- print '\tContinuing subprocess (verbose):'
+ print('\tNonblocking read of paused subprocess (should be empty):')
+ print(p.readPendingChars())
+ print('\tContinuing subprocess (verbose):')
if not p.cont(1): # verbose continue
- print '\t** Continue seems to have failed! Probly lost subproc...'
+ print('\t** Continue seems to have failed! Probly lost subproc...')
return p
else:
- print '\tReading accumulated line, blocking read:'
- print p.readline()
- print "\tDeleting subproc, which was set to die noisily:"
+ print('\tReading accumulated line, blocking read:')
+ print(p.readline())
+ print("\tDeleting subproc, which was set to die noisily:")
del p
- print "\tDone."
+ print("\tDone.")
return None