Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

subprocess.call() in Python

Status
Not open for further replies.

senmeis

Full Member level 3
Joined
Nov 26, 2014
Messages
161
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,477
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()“?
 

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.
 

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())
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top