【发布时间】:2013-11-21 05:01:06
【问题描述】:
我有一个运行其他 shell 脚本的 python (v3.3) 脚本。我的 python 脚本还打印诸如“关于运行脚本 X”和“完成运行脚本 X”之类的消息。
当我运行我的脚本时,我会将 shell 脚本的所有输出与我的打印语句分开。我看到这样的东西:
All of script X's output
All of script Y's output
All of script Z's output
About to run script X
Done running script X
About to run script Y
Done running script Y
About to run script Z
Done running script Z
我运行 shell 脚本的代码如下所示:
print( "running command: " + cmnd )
ret_code = subprocess.call( cmnd, shell=True )
print( "done running command")
我写了一个基本的测试脚本,做 *没有*看到这种行为。这段代码符合我的预期:
print("calling")
ret_code = subprocess.call("/bin/ls -la", shell=True )
print("back")
知道为什么输出没有交错吗?
【问题讨论】:
标签: python subprocess