【发布时间】:2016-02-19 17:19:15
【问题描述】:
我希望运行 Avconv 命令并将日志记录在一个文件中。在 Ubuntu 终端中,这可以在括号中的实际命令后使用 &>> 运算符完成,即
(avconv -i SRCFILE -ss 00:15:00 -t 00:30:00 TARGETFILE -threads auto) &>> LOGFILE
上述命令在终端运行时完美运行。
现在我有许多这样的命令要运行,我认为通过 Python 运行它们会很好。
-
我尝试使用
os.system(command_string)方式 ,它在运行时不会将 Avconv 输出打包到 LOGFILE 中,并且 avconv 命令似乎在 Python 脚本完成后执行 - 我为调试输入的一些字符串输出证明了这一点。我也收到了一些权限错误。这是输出的第一部分的样子AVCONV COMMAND EXECUTED sh: 1: : Permission denied sh: 1: : Permission denied sh: 1: PROGRAM DONE : Permission denied $ avconv version 11.2-6:11.2-1, Copyright (c) 2000-2014 the Libav developers built on Jan 18 2015 05:12:33 with gcc 4.9.2 (Ubuntu 4.9.2-10ubuntu2) Trailing options were found on the commandline. Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ... -
我还尝试使用
subprocess.call()方法,但出现以下错误(注意:所有文件都存在)Traceback (most recent call last): File "/home/usr/cnv.py", line 61, in <module> main() File "/home/usr/cnv.py", line 46, in main subprocess.call(newcmd) File "/usr/lib/python2.7/subprocess.py", line 522, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory
我希望运行多个(想想 50 多个)Avconv 命令,类似于顶部显示的版本,并将日志保存在文件中而不是标准输出中。我该怎么做 - 使用 Python 还是其他方式?
【问题讨论】: