def run(cmd, quiet=False, abandon_output=True): proc = Popen(split(cmd), stdout=PIPE, stderr=STDOUT) buf = Buffer(abandon_output=abandon_output) line = proc.stdout.readline() while len(line): buf.put(line) if not quiet: print(line, end='') line = proc.stdout.readline() # Process could probably close the descriptor before exiting. proc.wait() if proc.returncode != 0: raise Exception('Process exited with a non-zero return code. ' + 'Last output of the program:\n\n' + '---------- Start of exception log --\n' + buf.get_short().strip() + '\n---------- End of exception log --\n') return buf.get_long()
def run(cmd, quiet = False, abandon_output = True): proc = Popen(split(cmd), stdout = PIPE, stderr = STDOUT) buf = Buffer(abandon_output = abandon_output) line = proc.stdout.readline() while len(line): buf.put(line) if not quiet: print(line, end = '') line = proc.stdout.readline() # Process could probably close the descriptor before exiting. proc.wait() if proc.returncode != 0: raise Exception('Process exited with a non-zero return code. ' + 'Last output of the program:\n\n' + '---------- Start of exception log --\n' + buf.get_short().strip() + '\n---------- End of exception log --\n') return buf.get_long()