子进程命令的实时输出
subprocess.Popensubprocess.PIPE
是否有一种方法既可以存储输出(用于日志记录和错误检查),也可以生成实时流输出?
ret_val = subprocess.Popen( run_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True )output,
errors = ret_val.communicate()log_file.write(output)print outputif( ret_val.returncode ):
print "RUN failed\n\n%s\n\n" % (errors)
success = Falseif( errors ): log_file.write("\n\n%s\n\n" % errors)run_commandtee
ret_val = subprocess.Popen( run_command, stdout=log_file, stderr=subprocess.PIPE, shell=True )while not ret_val.poll(): log_file.flush()
tail -f log.txtlog_file = 'log.txt').
守着星空守着你
忽然笑
随时随地看视频慕课网APP
相关分类