OSError:[Errno 2]在Django中使用python子进程时,没有这样的文件或目录 [英] OSError: [Errno 2] No such file or directory while using python subprocess in Django

查看:276
本文介绍了OSError:[Errno 2]在Django中使用python子进程时,没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个程序,使用subprocess.call()...在python代码中进行一些系统调用...哪些引发以下错误,追溯

I am trying to run a program to make some system calls inside python code using subprocess.call() ... Which throws the following error , traceback

Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "/usr/lib/python2.7/subprocess.py", line 493, in call
      return Popen(*popenargs, **kwargs).wait()
      File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
      File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
      raise child_exception
      OSError: [Errno 2] No such file or directory

我的实际python代码如下,

My actual python code is as follows ,

url = "/media/videos/3cf02324-43e5-4996-bbdf-6377df448ae4.mp4"
real_path = "/home/chanceapp/webapps/chanceapp/chanceapp"+url
fake_crop_path = "/home/chanceapp/webapps/chanceapp/chanceapp/fake1"+url
fake_rotate_path = "/home/chanceapp/webapps/chanceapp.chanceapp/fake2"+url
crop = "ffmpeg -i %s -vf "%(real_path)+"crop=400:400:0:0 "+ "-strict -2 %s"%(fake_crop_path)
rotate = "ffmpeg -i %s -vf "%(fake_crop_path)+"transpose=1 "+"%s"%(fake_rotate_path)
move_rotated = "mv"+" %s"%(fake_rotate_path)+" %s"%(real_path)
delete_cropped = "rm "+"%s"%(fake_crop_path)
#system calls:
subprocess.call(crop)



Can i get some relevant advice on how to solve this .

推荐答案

如果您将一个字符串传递给子进程,则使用 shell = True 调用

Use shell=True if you're passing a string to subprocess.call.

docs


如果传递单个字符串,则 shell 必须是 True
否则字符串必须简单地命名要执行的程序,而
指定任何参数。

If passing a single string, either shell must be True or else the string must simply name the program to be executed without specifying any arguments.



subprocess.call(crop, shell=True)

或:

import shlex
subprocess.call(shlex.split(crop))

这篇关于OSError:[Errno 2]在Django中使用python子进程时,没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆