我正在使用Tkinter创建一个接口,将脚本连接到解释器,该角色将运行这些脚本。 我正在使用子进程模块popen(),它工作正常,但运行的结果显示在控制台窗口中。 我尝试将结果重定向到我界面中的文本区域,但控制台窗口仍然弹出,但这次是空的,只有在我关闭控制台窗口后,结果才显示在此文本区域中。 任何人都可以帮我弄清楚我做错了什么? 先谢谢你。
def interpreter1(): b=que2.get(block=True) a=que1.get(block=True) print "prameters are :" ,a ,b ,"\r\n" c='python C:\\workspace\\Project_Interpreter\\Tool-v1.0.py -s %s %s'%(b,a) ps=sp.Popen(['cmd','/K',c] , creationflags=0, shell=False, stdout=PIPE,stderr=sp.STDOUT,stdin=PIPE) texte01= ps.stdout.readlines()I am using Tkinter to create an interface that connects a script to the interpreter whom role is to run these scripts. I am using the subprocess module popen(), and it works fine but the result of the running is shown in a console window. I tried redirecting the result to a text zone in my interface, but the console window is still popping out but this time it is empty and the result shows up in this text zone only after I close the console window. Anybody can help me figure out what I did wrong ? thank you in advance.
def interpreter1(): b=que2.get(block=True) a=que1.get(block=True) print "prameters are :" ,a ,b ,"\r\n" c='python C:\\workspace\\Project_Interpreter\\Tool-v1.0.py -s %s %s'%(b,a) ps=sp.Popen(['cmd','/K',c] , creationflags=0, shell=False, stdout=PIPE,stderr=sp.STDOUT,stdin=PIPE) texte01= ps.stdout.readlines()最满意答案
您可以使用subprocess.STARTUPINFO类来隐藏控制台窗口中的文本。 它可以作为选项传递给subprocess.Peopen()。 尝试这个:
def interpreter1(): b=que2.get(block=True) a=que1.get(block=True) print "prameters are :" ,a ,b ,"\r\n" c='python C:\\workspace\\Project_Interpreter\\Tool-v1.0.py -s %s %s'%(b,a) startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW ps=sp.Popen(['cmd','/K',c] , creationflags=0, shell=False, startupinfo=startupinfo, stdout=PIPE, stderr=sp.STDOUT, stdin=PIPE) texte01= ps.stdout.readlines()You can use the subprocess.STARTUPINFO class to hide the text from the console window. It can be passed as an option to subprocess.Peopen(). Try this:
def interpreter1(): b=que2.get(block=True) a=que1.get(block=True) print "prameters are :" ,a ,b ,"\r\n" c='python C:\\workspace\\Project_Interpreter\\Tool-v1.0.py -s %s %s'%(b,a) startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW ps=sp.Popen(['cmd','/K',c] , creationflags=0, shell=False, startupinfo=startupinfo, stdout=PIPE, stderr=sp.STDOUT, stdin=PIPE) texte01= ps.stdout.readlines()更多推荐
发布评论