def process(self, cmd=[], input=None, timeout=None):
proc = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.logger.info('Running process, pid=%d: %s' % (proc.pid, str(cmd)))
try:
output, err = proc.communicate(input, timeout=timeout)
except subprocess.TimeoutExpired as e:
self.logger.warning(
'Process %d killed with timeout %s' % (proc.pid, str(timeout)))
proc.kill()
output, err = proc.communicate()
self.logger.debug("stdout: " + repr(output))
self.logger.debug("stderr: " + repr(err))
stdout = output.decode('utf-8')
stderr = err.decode('utf-8')
if proc.returncode != 0:
self.logger.warning(
'Process %d failed with rcode %d' % (proc.pid, int(proc.returncode)))
else:
self.logger.debug('Process %d finished with rcode 0' % (proc.pid))
return int(proc.returncode), stdout, stderr
评论列表
文章目录