使用Pyinstaller的Python子进程Popen

问题描述 投票:5回答:1

我使用ffmpeg转换一些视频。我用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()

我用这种方法杀了

self.my_pro.kill()

这是没有编译到exe的okey。

但我编译与pyinstaller--noconsole子进程无法正常工作。我必须将subprocess.Popen(...)改为subprocess.check_output(...)

但是这次我不能用self.my_pro.kill()杀死进程这不起作用。

我怎么可以运行进程,我可以杀死它将运行pyinstaller noconsole?

python subprocess pyinstaller
1个回答
3
投票

正如@jfs所写,使用Popen你必须重定向一切。你忘了stdout

所以这段代码不再对我崩溃:

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)
© www.soinside.com 2019 - 2024. All rights reserved.