I'm using Python 3.x on Windows 10. I'm using a subprocess to execute a command to use FFmpeg to create a slideshow from some images. It normally works fine except for when the output file already exists. When this happens I get a message on stderr prompting the user if it should overwrite. This message does not end in a newline. Here's the code I'm currently using
with subprocess.Popen([FFMPEG_PATH,
'-i', 'img_%03d.png',
'-vf', vfCommand,
'-hide_banner',
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'{0}'.format(vidOutputPath)]
, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as outProcess:
while outProcess.poll() is None:
data = outProcess.stdout.read(1)
data = data.decode()
print(data, end='')
Using print(data, end='') on the last line I will see everything nicely formatted but it will not show the "File exists overwrite [y/N]" prompt. whereas if just do a print(data) then the prompt will show, just one character on a line.
My end goal is to show the command and allow a user to respond to it. I do not want to use shell=true as that opens up the program to injection issue and if possible I don't want to do anything where I have to install/download additional packages for python. I'd like to keep this where even a basic user could install python and immediately use the program.