Question

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()
Was it helpful?

Solution

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top