I have the below code which runs a couple of command line applications. If I then try to kill the process, sometimes it works, sometimes it doesn't and the process continues to run. I just wanted to check if what I am doing is the correct, preferred method? I am running on Windows 7 and Windows Server 2012, Python 2.7.11, all 64bit.
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
environ1 = os.environ.copy()
environ1['FFREPORT'] = 'level=32:file={}'.format(ffmpeglogFilePath)
self.ffmpeglogFilePath1 = ffmpeglogFilePath
self.process1a = Popen(command1, stdout=PIPE, startupinfo=startupinfo)
self.process1b = Popen(command2, stdin=self.process1a.stdout, startupinfo=startupinfo, env=environ1)
def killProcess1(self, running_pane1):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
Popen("TASKKILL /F /PID {pid} /T".format(pid=self.process1a.pid), startupinfo=startupinfo)
Popen("TASKKILL /F /PID {pid} /T".format(pid=self.process1b.pid), startupinfo=startupinfo)