Python Subprocess Popen with Pyinstaller

2019-02-17 21:44发布

问题:

I use ffmpeg for converting some videos. I am calling command with subprocess.Popen(...)

si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW

self.my_pro = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
startupinfo=si)

(output, error) = self.my_pro.communicate()

and i kill with this method

self.my_pro.kill()

It's okey without compile to exe.

But i compiled with pyinstaller with --noconsole subprocess not working. I must change subprocess.Popen(...) to subprocess.check_output(...)

But this time i can't kill process with self.my_pro.kill() this not working.

How i can run process with i can kill and it will run pyinstaller noconsole?

回答1:

As @jfs wrote, with Popen you have to redirect everything. You forgot stdout

So this code doesn't crash for me anymore:

si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW

self.my_pro = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
startupinfo=si)