0

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)
speedyrazor
  • 3,127
  • 7
  • 33
  • 51
  • Why are you trying to kill processes instead of signaling termination, and waiting for them to finish? – IInspectable Feb 02 '16 at 19:27
  • Is that a better way to stop a running process? How would you signal termination? – speedyrazor Feb 02 '16 at 19:44
  • [GenerateConsoleCtrlEvent](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683155.aspx). Assuming the command line application honors [Ctrl]+C and terminates. It's a bit involved. Details under [Can I send a ctrl-C (SIGINT) to an application on Windows?](http://stackoverflow.com/q/813086/1889329) – IInspectable Feb 02 '16 at 20:41
  • That is very involved. Any python solution to this problem? – speedyrazor Feb 03 '16 at 22:47

0 Answers0