简体   繁体   English

Python子进程错误没有这样的文件或目录

[英]Python Subprocess Error No Such File or Directory

Hello I can't get my script to run it is meant to steam my screen live over HTTP but it comes up with an error I can't seem to fix. 您好,我无法让我的脚本运行,它的目的是通过HTTP实时显示我的屏幕,但是它出现了一个我似乎无法修复的错误。

#!/bin/python
import subprocess
import threading

try:
    subprocess.Popen("rm out.mpg")
except OSError:
    pass

subprocess.Popen("ffmpeg -f x11grab -framerate 60 -video_size 1366x768 -i :0.0 out.mpg")
subprocess.Popen("python -m SimpleHTTPServer 8000 out.mpg")

The error is 错误是

Traceback (most recent call last):
  File "Streaming.py", line 11, in <module>
    subprocess.Popen("ffmpeg -f x11grab -framerate 60 -video_size 1366x768 -i :0.0 out.mpg")
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

The command arguments for Popen should be a sequence of strings. Popen的命令参数应为字符串序列。 Try this: 尝试这个:

import subprocess
subprocess.Popen(["ffmpeg", "-f", "x11grab", 
                  "-framerate", "60", "-video_size",
                  "1366x768", "-i", ":0.0", "out.mpg"])

Note that the first string that contains the name of the command should not contain any spaces! 需要注意的是包含命令名称的第一个字符串不应包含任何空格! If you would use "ffmpeg " (note the space at the end) instead of "ffmpeg" it would fail again with a "no such file or directory" error because there is no command with the name "ffmpeg "! 如果您使用“ ffmpeg”(注意末尾的空格)而不是“ ffmpeg”,它将再次失败,并显示“无此类文件或目录”错误,因为没有名称为“ ffmpeg”的命令!

You could also use shlex : 您还可以使用shlex

import subprocess
import shlex

cmd = "ffmpeg -f x11grab -framerate 60 -video_size 1366x768 -i :0.0 out.mpg"
subprocess.Popen(shlex.split(cmd))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM