Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Subprocess Popen with Pyinstaller

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?

like image 289
Soner B Avatar asked Oct 19 '22 00:10

Soner B


1 Answers

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)
like image 175
pagep Avatar answered Oct 21 '22 15:10

pagep