def run_foreground(command, env=None):
if DEBUG:
print("DEBUG: Executing {}".format(command))
cmd_env = os.environ.copy()
if env is not None:
cmd_env.update(env)
p = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, env=cmd_env)
try:
for line in iter(p.stdout.readline, b''):
print(line.rstrip().decode('utf-8'))
# send Ctrl-C to subprocess
except KeyboardInterrupt:
p.send_signal(signal.SIGINT)
for line in iter(p.stdout.readline, b''):
print(line.rstrip().decode('utf-8'))
raise
finally:
p.wait()
return p.returncode
评论列表
文章目录