0
我想從Python運行一個C程序與子進程模塊,捕獲其變量輸出。代碼看起來是這樣的:Python:subprocess.communicate():ValueError與打印()函數,但不是「打印」內置
process = Popen(["myprog", str(length), filename], stdout=PIPE, stderr=PIPE)
#wait for the process
result = process.communicate()
end=time()
print result
上面的代碼工作 - result
被示爲myprog
的標準輸出輸出和stderr輸出(字符串)的2元組。
... 然而如果我改變print result
到print(result)
...
Traceback (most recent call last):
File "tests.py", line 26, in <module>
print(result)
ValueError: I/O operation on closed file
我在這裏完全難倒,我甚至不知道從哪裏開始試圖解釋這個!當然,我的程序無論如何都適用,但我真的很想知道爲什麼會發生這種情況,並希望這會是一個有趣的問題。
請你向我們展示了整個Python和整個C程序? – User