Python3 Subprocess.run 找不到相关引用文件 [英] Python3 Subprocess.run cannot find relative referenced file

查看:57
本文介绍了Python3 Subprocess.run 找不到相关引用文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 subprocess.run(),它使用一个参数将文件引用为 "./0.mkv"

I'm using subprocess.run() that uses an argument that references a file as "./0.mkv"

它告诉我它找不到文件./0.mkv",我需要引用整个路径还是有办法让 ./ 正确引用?

It tells me it cannot find the file "./0.mkv", do I need to reference the entire path or is there a way to make ./ refer correctly?

或者可能完全是别的东西,我不确定.

Or maybe it's something else entirely, I'm not sure.

这是实际代码:

temp_file_path = "./0.mkv"
final_file_path = "./0hardsubs.mkv"

cmd = ['ffmpeg', '-i', f'"{temp_file_path}"', \
       '-filter_complex', f'"subtitles=\'{temp_file_path}\'"', \
       f'"{final_file_path}"', '-y', '-loglevel', 'warning', '-stats']

subprocess.run(cmd)

这是输出:

"./0.mkv": No such file or directory

推荐答案

事实证明这是另一回事.我尝试了 print(os.path.getsize(temp_file_path)) 并收到了正确的输出,因此 Python 显然能够看到该文件.

Turns out this was something else. I tried print(os.path.getsize(temp_file_path)) and recieved the correct output so Python was clearly able to see the file.

一旦我删除了 ffmpeg 输入周围的双引号,过滤和输出一切正常.不确定这怎么可能,但我想这是 subprocess.run 的一个特性,它会自动清理参数?

Once I removed the double quotes around the ffmpeg input, filter and output everything worked fine. Not sure how that's possible but I guess that's a feature of subprocess.run that it sanitises the arguments automatically?

对于任何感兴趣的人,这是最终输出:

For anyone interested, here's the final output:

temp_file_path = "./0.mkv"
final_file_path = "./0hardsubs.mkv"

cmd = ['ffmpeg', '-i', f'{temp_file_path}', \
       '-filter_complex', f'subtitles=\'{temp_file_path}\'', \
       f'{final_file_path}', '-y', '-loglevel', 'warning', '-stats']

subprocess.run(cmd)

这篇关于Python3 Subprocess.run 找不到相关引用文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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