python - 从 django 查看脚本运行 linux 命令

标签 python django bash pythonanywhere avconv

我尝试在我的网络应用程序中使用avconv(Django on pythonanywhere)。我必须从视频文件中提取缩略图。 使用 bash 控制台,我可以运行:

avconv -ss 00:01:00 -i myapp/myapp/media/inputvide.mp4 -vsync 1 -t 0.01 myapp/myapp/media/videothumb.png

这很好用。 当我想通过脚本(view.py)使用此命令时,我尝试过:

cmd = 'avconv -ss 00:01:00 -i '+inputfile+' -vsync 1 -t 0.01 '+outputfile
os.system(cmd)

inputfile 是我的视频的路径,outputile 是我的视频 + '.png' 的路径 没有抛出任何错误,但我在文件夹中的任何位置都找不到输出文件?

有什么想法吗?

谢谢!

最佳答案

您可以尝试使用子流程库:

from subprocess import call

success = call('avconv -ss 00:01:00 -i '+inputfile+' -vsync 1 -t 0.01'+outputfile, shell=True)

if success != 0:
    //The command has failed

关于python - 从 django 查看脚本运行 linux 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42019413/

相关文章:

python - 如何为使用日期时间的导入函数设置时间?

python - 如何在django中检索特定模型的所有权限?

python - 'itertools' 文件在哪里

django - 我可以创建一个表单和 View 的文件夹并使用 __init__.py 文件(如模型和测试)吗?

python - 在Django中使用计数功能获取数据

django - 在不提供 app_name 的情况下在 include() 中指定命名空间 ' django.core.exceptions.ImproperlyConfigured

mysql - 如何捕获MySQL客户端发出的系统命令的返回值

c++ - 无法在 Bash for Windows 中通过管道输出

python - 树莓派 : issue communicating via I2C

bash 脚本重复数据删除