0

When the process is running we can use returncode to check its state.

p = subprocess.Popen(command, shell=True)
   retrun_code =p.wait()
   print(retrun_code)

The documentation for the returncode attribute says:

The child return code, set by poll() and wait() . if it is None value indicates that the process hasn’t terminated yet.

I am running FFmpeg commands using a subprocess. In some cases, when a file already exists, it will prompt to confirm overwrite.

File 'output.mp4' already exists. Overwrite? [y/N]

Similar to return code, how can I check when the prompt is shown in the process? More Precisely, How do I tell if process is running or waiting for user input?

itsRits
  • 3
  • 3
  • 1
    You'd have to a program that concurrently & continuously processes `stdout` and `stdin` like a human would, which would be notably more complex. It'd be much easier to choose ahead of time whether to always/never overwrite existing files, passing in `-y`/`-n` option accordingly, see: https://stackoverflow.com/questions/39788972/ffmpeg-overwrite-output-file-if-exists – Kache Jun 22 '23 at 23:05

1 Answers1

0

wrap your command with the yes command.

yes | ffmpeg -blah

or use the -y flag on ffmpeg.

WombatPM
  • 2,561
  • 2
  • 22
  • 22