我寫了非常小的腳本並嘗試捕獲腳本的輸出。我寫了多個時間類似的方式,但從來沒有問題。我可以提供意見嗎?我覺得我做的很愚蠢的錯誤捕獲Python腳本輸出
numpy_temp = """
import numpy
import sys
a, b, c = numpy.polyfit(%s,%s, 2)
print a, b, c""" %(x, y)
fp_numpy = open("numpy_temp.py", "w")
fp_numpy.write(numpy_temp)
cmd = "/remote/Python-2.7.2/bin/python numpy_temp.py "
proc = subprocess.Popen(cmd, stdout = subprocess.PIPE,
stderr = subprocess.PIPE, shell = True)
out, err = proc.communicate()
print "out", out
也許你實際上得到了stderr反應。嘗試'打印出來,錯誤',看看你有什麼。 – sberry