小编典典

OSError:[Errno 2]在Django中使用python子进程时,没有此类文件或目录

django

我正在尝试运行一个程序来使用Python代码在subprocess.call()其中进行一些系统调用,从而引发以下错误:

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代码如下:

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)

我可以获取有关如何解决此问题的一些建议吗?


阅读 544

收藏
2020-03-28

共1个答案

小编典典

使用shell=True,如果你传递一个字符串subprocess.call

从文档:

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

subprocess.call(crop, shell=True)

要么:

import shlex
subprocess.call(shlex.split(crop))
2020-03-28