python - 子进程“没有这样的文件或目录”
问题描述
我究竟做错了什么?我有一个可以在命令行中运行的命令,它可以在一个有效的目录中找到所有视频文件的总持续时间。
find /Volumes/Storage/test -maxdepth 1 -iname '*.mp4' -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \; | paste -sd+ -| bc
它工作正常,它输出秒数> 456.766000,这是我想要的。
现在,当我编写 python 脚本来执行它时,它说No such file or directory
并且不输出命令行命令最终执行的数字行。
代码
import subprocess
result2 = subprocess.run(['find', '/Volumes/Storage/test -maxdepth 1 -iname \'*.mp4\' -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \; | paste -sd+ -| bc'])
print (result2)
print ("-------")
错误:
No such file or directory
find: /Volumes/Storage/test -maxdepth 1 -iname '*.mp4' -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \; | paste -sd+ -| bc: No such file or directory
CompletedProcess(args=['find', "/Volumes/Storage/test -maxdepth 1 -iname '*.mp4' -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \\; | paste -sd+ -| bc"], returncode=1)
Shlex 输出
['find', '/Volumes/Storage/test', '-maxdepth', '1', '-iname', '*.mp4', '-exec', 'ffprobe', '-v', 'quiet', '-of', 'csv=p=0', '-show_entries', 'format=duration', '{}', ';', '|', 'paste', '-sd+', '-|', 'bc']
解决方案
Here's the solution that worked for me:
# Python program to explain os.system() method
# importing os module
import os
# Command to execute
cmd = 'find /Volumes/Storage/test -maxdepth 1 -iname \'*.mp4\' -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \; | paste -sd+ -| bc'
# Using os.system() method
out = os.popen(cmd).read()
print("Output:",out)
推荐阅读
- javascript - 加入http结果
- c# - HttpClient长轮询被单独的线程中断
- sql - 设计用户如何创建邀请以供其他人接受并开始并能够完成邀请
- c# - 将 SqlConnection 作为 IDbConnection 返回
- c# - 如何在asp.net mvc中修复404“找不到资源”
- google-apps-script - 删除最后一个非空行之后的所有行
- java - 如何将 HTML 中的 href 值传递给 Thymeleaf?
- python - 从 api dict 响应中获取价值
- caching - .NET Core 下拉 NuGet 包到用户缓存
- python - 作为命令行参数传入时,三重积分函数不起作用