Jan 11, 2023 #1 S senmeis Full Member level 3 Joined Nov 26, 2014 Messages 167 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,296 Activity points 2,521 Hi, I want to use Python: subprocess.call(["ffmpeg", "-i", "test.mp4", "test.mp3"]) to make a media conversion. Question: how can I redirect the console output so that this can be outputted with „print()“?
Hi, I want to use Python: subprocess.call(["ffmpeg", "-i", "test.mp4", "test.mp3"]) to make a media conversion. Question: how can I redirect the console output so that this can be outputted with „print()“?
Jan 11, 2023 #2 A Aussie Susan Advanced Member level 5 Joined Jan 5, 2015 Messages 1,610 Helped 415 Reputation 830 Reaction score 474 Trophy points 1,363 Activity points 19,085 subprocess — Subprocess management Source code: Lib/subprocess.py The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace seve... docs.python.org Upvote 0 Downvote
subprocess — Subprocess management Source code: Lib/subprocess.py The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace seve... docs.python.org
Jan 12, 2023 #3 S senmeis Full Member level 3 Joined Nov 26, 2014 Messages 167 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,296 Activity points 2,521 I tried the following two alternatives: Alternative 1: Python: out = subprocess.run(["ffmpeg", "-i", "test.mp4", "test.mp3"], capture_output=True, text=True, shell=True) print(out.stdout) Alternative 2: Python: out = subprocess.check_output(["ffmpeg", "-i", "test.mp4", "test.mp3"], shell=True) print(out.decode('utf-8')) but both don’t print out anything. I just want to get the process info which comes from the console when ffmpeg is executed. Upvote 0 Downvote
I tried the following two alternatives: Alternative 1: Python: out = subprocess.run(["ffmpeg", "-i", "test.mp4", "test.mp3"], capture_output=True, text=True, shell=True) print(out.stdout) Alternative 2: Python: out = subprocess.check_output(["ffmpeg", "-i", "test.mp4", "test.mp3"], shell=True) print(out.decode('utf-8')) but both don’t print out anything. I just want to get the process info which comes from the console when ffmpeg is executed.
Jan 31, 2023 #4 R Risso Newbie level 5 Joined Jan 31, 2023 Messages 9 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 83 You can use the subprocess.PIPE to redirect the console output to your program. For example: process = subprocess.Popen(["ffmpeg", "-i", "test.mp4", "test.mp3"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) Code: for line in iter(process.stdout.readline, b''): print(line.decode('utf-8').rstrip()) Upvote 0 Downvote
You can use the subprocess.PIPE to redirect the console output to your program. For example: process = subprocess.Popen(["ffmpeg", "-i", "test.mp4", "test.mp3"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) Code: for line in iter(process.stdout.readline, b''): print(line.decode('utf-8').rstrip())