def run_cmd(self, params):
def convert_line(line):
line = to_str(line)
return line.strip() + '\r\n'
try:
self.process = run(self.cmd, async=True, stdin=self.stdin, outfile=self.outfile,
env_vars=self.env_vars, inherit_cwd=self.inherit_cwd)
if self.outfile:
if self.outfile == subprocess.PIPE:
# get stdout/stderr from child process and write to parent output
for line in iter(self.process.stdout.readline, ''):
if not (line and line.strip()) and self.is_killed():
break
line = convert_line(line)
sys.stdout.write(line)
sys.stdout.flush()
for line in iter(self.process.stderr.readline, ''):
if not (line and line.strip()) and self.is_killed():
break
line = convert_line(line)
sys.stderr.write(line)
sys.stderr.flush()
self.process.wait()
else:
self.process.communicate()
except Exception as e:
if self.process and not self.quiet:
LOGGER.warning('Shell command error "%s": %s' % (e, self.cmd))
if self.process and not self.quiet and self.process.returncode != 0:
LOGGER.warning('Shell command exit code "%s": %s' % (self.process.returncode, self.cmd))
评论列表
文章目录