简体   繁体   English

使用Pyinstaller的Python子进程Popen

[英]Python Subprocess Popen with Pyinstaller

I use ffmpeg for converting some videos. 我使用ffmpeg转换一些视频。 I am calling command with subprocess.Popen(...) 我用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. 这是没有编译到exe的okey。

But i compiled with pyinstaller with --noconsole subprocess not working. 但我编译与pyinstaller--noconsole--noconsole无法正常工作。 I must change subprocess.Popen(...) to subprocess.check_output(...) 我必须将subprocess.Popen(...)更改为subprocess.check_output(...)

But this time i can't kill process with self.my_pro.kill() this not working. 但是这次我不能用self.my_pro.kill()来杀死进程。

How i can run process with i can kill and it will run pyinstaller noconsole? 我怎么可以运行进程,我可以杀死它将运行pyinstaller noconsole?

As @jfs wrote, with Popen you have to redirect everything. 作为@jfs写道,与Popen你要重定向一切。 You forgot stdout 你忘记了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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM