python执行shell实时输出,并返回code教程
cmd = subprocess.Popen(shell, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
stdout=subprocess.PIPE, universal_newlines=True, shell=True, bufsize=1)
# 实时输出
while True:
line = cmd.stdout.readline()
if print_flag:
print(line)
if subprocess.Popen.poll(cmd) == 0: # 判断子进程是否结束
break
code = cmd.returncode
return code
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »