0
ffmpeg -f gdigrab -framerate 30 -i desktop -c:v h264_nvenc -qp 0 output.mkv

Hi there. That's my shell command that capture data from screen.
My command is waiting for press q, and when i press q command stops. For ex i want to run my command through subprocess.Popen and stop it in 5 seconds.
How can i do that?

Barry Alen
  • 39
  • 5
  • 3
    If you do `dir(...)` on the object returned by `Popen`, you will see all of its methods. One of these methods will *terminate* the process (provided that the signal is not intercepted), another one will definitively *kill* it. I will leave you to discover the names of the aforementioned two methods... – alani Sep 29 '20 at 08:28
  • BTW, you may wish to try to *terminate* the process, then wait for (say) a second to allow it to shut down cleanly, and then *kill* it in case it hasn't already died. If your python script is going to end soon after this, then that's all you need to do. Otherwise (e.g. if you're running this in a loop), you might also to want to use the `wait` method to avoid accumulating zombie processes. – alani Sep 29 '20 at 08:36
  • Does this answer your question? [Executing command line programs from within python](https://stackoverflow.com/questions/450285/executing-command-line-programs-from-within-python) – Tomerikoo Sep 29 '20 at 08:44
  • @alani, i will try to use terminate method. i can't kill the process because seems like will be some errors in my output file. I have to shut down my process cleanly. – Nikto Sep 29 '20 at 09:05
  • @alani, Barry alen it's my second account – Nikto Sep 29 '20 at 09:34

0 Answers0