简体   繁体   English

使用 mediainfo 在 python3 中运行 check_output 会产生错误,即使终端中的相同调用工作正常

[英]Running a check_output in python3 with mediainfo produces an error, even though the same call in terminal works fine

This is the code:这是代码:

try:
    s = check_output(['mediainfo', '--Inform=General;%Format%', filename])  # Gets the output from mediainfo

When running it, I get运行它时,我得到

subprocess.CalledProcessError: Command '['mediainfo', '--Inform=General;%Format%', 'xyz']' returned non-zero exit status 1

When running mediainfo --Inform='Video;%Format%' s03e07.mkv in a terminal, I get the desired output though, so what's going on here?mediainfo --Inform='Video;%Format%' s03e07.mkv运行mediainfo --Inform='Video;%Format%' s03e07.mkv时,虽然我得到了所需的输出,那么这里发生了什么?

There is nothing wrong with the first two arguments.前两个论点没有错。 there are two strong possibilities, you are reading from a file and you have trailing whitespace on the filename:有两种很强的可能性,您正在从文件中读取数据并且文件名上有尾随空格:

"sample.mkv\n"

Or you current working directory is not where the file is so you need to pass the full path or set cwd="path_to_filr_dir" in check_output call.或者您当前的工作目录不是文件所在的位置,因此您需要传递完整路径或在check_output调用中设置cwd="path_to_filr_dir"

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

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