【问题标题】:python script only works when I close the consolepython脚本仅在我关闭控制台时才有效
【发布时间】:2014-01-27 16:03:27
【问题描述】:

我正在使用 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()

【问题讨论】:

    标签: python tkinter stdout popen


    【解决方案1】:

    您可以使用 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-22
      • 2016-01-03
      • 1970-01-01
      • 1970-01-01
      • 2015-06-04
      相关资源
      最近更新 更多