python脚本中的os.system出错

时间:2015-05-25 20:13:12

标签: python ffmpeg os.system

我正在创建一个python脚本,它将使用ffmpeg和unoconv转换文件。但是,当我运行程序时,程序只显示文本:

,而不是获取转换后的文件
sh: 1: unoconv -f: not found

以下是我的程序的脚本:

    path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
    os.chdir(path[1:-2])
    filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
    Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. .mp3: ")
    body, ext = os.path.splitext("filename")
    os.system("'ffmpeg -i ' + filename + body + Fileextension ")

关于为什么会发生这种情况的任何想法?

2 个答案:

答案 0 :(得分:1)

看看你的命令:

os.system("'ffmpeg -i ' + filename + body + Fileextension ")

您尝试执行此文字字符串。

尝试:

os.system('ffmpeg -i ' + filename + body + Fileextension)

此外,建议使用subprocess代替os.system

答案 1 :(得分:0)

您应该使用子进程模块,特别是subprocess.check_call传递args列表:

from subprocess import check_call
check_call(["ffmpeg" ,"-i",filename + body + Fileextension])

任何非零退出代码都会引发CalledProcessError