我想在python文件中运行终端命令。它工作正常,我也可以使用subprocess.Popen在gui窗口上获取终端消息。
import subprocess
import wx
import os
def main():
p = subprocess.Popen(['ls'], stdout = subprocess.PIPE)
text = p.stdout.readlines()
text = "".join(text)
wx.MessageBox("file names:\n%s" % text, "info")
if __name__ == '__main__':
app = wx.PySimpleApp()
main()
但是当我运行一个命令,哪个终端应该问一些问题的答案时,我收到错误?
Traceback (most recent call last):
File "to_make_new_project_folder.py", line 19, in <module> main()
File "to_make_new_project_folder.py", line 10, in main p = subprocess.Popen(['gr_modtool add -t general square_ff'], stdout = subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 711, in init errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1308, in _execute_child raise child_exception
OSError: [Errno 2] No such file or directory
有人知道如何使用gui窗口从终端回答问题吗?
答案 0 :(得分:0)
你应该尝试传入stdin = PIPE以及popen
答案 1 :(得分:0)
根据您的堆栈跟踪,您收到的错误为OSError: No such file or directory
,来自subprocess
。在我看来,Popen
无法找到您尝试执行的文件,因此失败了。