How to pass commands to an application from python

霸气de小男生 提交于 2019-12-12 04:48:58

问题


I am trying to run ffmpeg application from python.I am using the following code to execute the application

import subprocess
subprocess.call(['C:/ffmpeg/bin/ffmpeg.exe'])

by this command the application is getting executed. could somebody tell me how can i pass commands to the application, i tried

subprocess.call(['C:/ffmpeg/bin/ffmpeg.exe','ffmpeg -i 2.mp4 -vn -ab 128 outputaudio.mp3'])

but its not working.


回答1:


They need to be individual args:

subprocess.check_call(['C:/ffmpeg/bin/ffmpeg.exe','ffmpeg','-i',"2.mp4","-vn", "-ab", "128", "outputaudio.mp3"])

Also use check_call instead of call, check_call will raise a CalledProcessError if the command returns a non-zero exit status. I am not sure the 'ffmpeg' should be there.




回答2:


The arguments should each be separate elements in the list. The doc page has an example of how to call it. Yours should be something like this:

['C:/ffmpeg/bin/ffmpeg.exe','ffmpeg','-i 2.mp4','-vn','-ab','128','outputaudio.mp3']


来源:https://stackoverflow.com/questions/29434608/how-to-pass-commands-to-an-application-from-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!