使用 Pyinstaller 的 Python 子进程 Popen

2023-11-21

我使用 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就可以了。

但我编译了pyinstaller with --noconsole子进程不工作。 我必须改变subprocess.Popen(...) to subprocess.check_output(...)

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

我如何使用 i can kill 运行进程并且它将运行 pyinstaller noconsole?


正如@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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Pyinstaller 的 Python 子进程 Popen 的相关文章

随机推荐