相关疑难解决方法(0)

Python subprocess.Popen()错误(没有这样的文件或目录)

我试图使用Python函数计算文件中的行数.在当前目录中,当os.system("ls")找到文件时,命令subprocess.Popen(["wc -l filename"], stdout=subprocess.PIPE)不起作用.

这是我的代码:

>>> import os
>>> import subprocess
>>> os.system("ls")
sorted_list.dat
0
>>> p = subprocess.Popen(["wc -l sorted_list.dat"], stdout=subprocess.PIPE)File "<stdin>", line 1, in <module>
File "/Users/a200/anaconda/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
File "/Users/a200/anaconda/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)

python subprocess system popen

19
推荐指数
2
解决办法
3万
查看次数

OSError:使用subprocess.Popen时没有这样的文件或目录

我想要获取视频片段的持续时间.但它无法获取文件.这是我的代码:

import subprocess
import os
def getLength(input_video):
    result = subprocess.Popen('ffprobe -i input_video -show_entries format=duration -v quiet -of csv="p=0"', stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
    output = result.communicate()
    return output[0]
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
x = (os.path.join(BASE_DIR,'uploads/video.mkv'))
getLength(x)
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

Traceback (most recent call last):
  File "/home/aman/Desktop/stream/src/stream/uploads/sadf.py", line 9, in <module>
    getLength(x)
  File "/home/aman/Desktop/stream/src/stream/uploads/sadf.py", line 4, in getLength
    result = subprocess.Popen('ffprobe -i input_video -show_entries format=duration -v quiet -of csv="p=0"', stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno …
Run Code Online (Sandbox Code Playgroud)

python subprocess

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×2

subprocess ×2

popen ×1

system ×1