Python 子进程输出

Python subprocess output

我在 python 中使用子进程来捕获来自 bazel 应用程序张量流的结果。

import subprocess
cmd = ["bazel-bin/tensorflow/examples/label_image/label_image"]
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
output = pipe.communicate()[0]
print "Result: ", output

问题是结果出现在终端中,我无法在变量中捕获它'output'

和returns结果:(无)

已在评论中解决:

Try also capturing stderr with stderr=subprocess.PIPE and output, err = pipe.communicate() and see what is in err. – sberry