我的問題是關于子流程的。我正在使用子進程來調用外部程序,我使用了 check_output() 方法,其中我將參數作為列表傳遞。我注意到,當從交互式 shell 中使用 check_output() 時,需要 3 分鐘(在我的情況下,這是執行外部程序的正確時間 [如果進程保持阻塞等待響應,則沒有問題])當我在 python 腳本中使用相同的方法和相同的參數時,可能需要長達 1 小時!以前有人遇到過這種情況嗎?有什么建議嗎?有關信息,我在 Debian 10 上使用 Python3.7.3。感謝是提前的- - 編輯:我的代碼沒有什么特別的我的腳本只是:from subprocess import check_outputtry: #commandList is the programm (external bin) I would excute with its params result = check_output(commandList) print(result.decode("latin-1"))except Exception as e: print(e)
1 回答

30秒到達戰場
TA貢獻1828條經驗 獲得超6個贊
使用subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess. STDOUT, shell=True)
解決了問題。
添加回答
舉報
0/150
提交
取消