Thursday 15 August 2013

python - os.system to subprocess.Popen or subprocess.call -


I have a function below that is working fine when I execute my python code in CMD (Simit an execution Is worthy). However, when I made my executable with py2exe, a shell window is quickly visible and disappears. So I searched and found that I subprose. I can use with PeptenelFlegs = 0x08000000. But it does not work.

This is my function

  def kill (SIMT): outfile1 = open ('kill.txt', 'w') outfile1.write ('kill' + ' \ R \ n ') outfile1.write (' x ') outfile1.close () os.system ("Type Kill.txt | testclient p." + Symit) os.remove (' Kill.txt ')  

And I changed the os.system with this:

  subprocess. POPEAN (["type kill.txt | testclient p.", SIMT], Creationflags = 0x08000000, shell = True) .community ()  

Also, should I have shell = true ?

If you want to arrange the shell for the pipeline for you, you will see the shell = True and is the first argument to be a string, as if you did it for the ossystem , no list. With shell = False , the execution of the list given to the list given to the list as the first item of the list is, in the form of command-line arguments; So you have the first item in | can not be and hopefully Shell will be able to arrange on your behalf.

Your choice is to make "pipeline" or its equivalent - for example, perhaps the simplest here, as the standard input of the sub process ( stdin = ) A file object has been opened on Kill.txt . Popin which executes only testclient (I believe the type reads the file in the standout, but should be sufficient in case of this specific use ).


No comments:

Post a Comment