我使用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?
正如@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)