0
# Create a new terminal window and run the ffmpeg command in it
cmd = ' '.join(ffmpeg.compile(output_stream, overwrite_output=True))
compressing = subprocess.Popen('start cmd /k {}'.format(cmd), shell=True)

while compressing.poll() is None: #check if the process is still running
    print('Processing video...')
    break
else:
    if compressing.returncode == 0: #check if the process was canceled by the user
       print('Video processing canceled by user!')
    else: #if the process was completed successfully
        print('Video processing complete!')

I want to check if the process (terminal) was closed by the user it should print that sentence, however it's always stuck at "Processing Video" even if the user kills the subprocess terminal

Mohamed Darwesh
  • 659
  • 4
  • 17
  • 1
    Your loop never iterates more than once with the unconditional `break` statement there. Why do you have it? – chepner Mar 08 '23 at 20:24
  • @chepner This is a simplified version of a bigger code, however I wanted the text to appear only once to save resources and for some reason without the break statement the program goes directly to the if statement (the process is still running) – Mohamed Darwesh Mar 08 '23 at 21:12
  • I think it's because you aren't monitoring `cmd`, which is running in the background, but `start` (or the shell that executes `start`), which terminates as soon as it has started `cmd`. – chepner Mar 08 '23 at 21:14
  • Why not skip the shell and use `list(ffmpeg.compile(...))` directly as the command to run? – chepner Mar 08 '23 at 21:15
  • @chepner It could be that I'm monitoring the shell indeed I gotta check that. However I'm using a shell because this is a part of a GUI program so once the user presses a button it should open a new terminal and shows him progress..that's why – Mohamed Darwesh Mar 08 '23 at 21:25

0 Answers0