首页 > 解决方案 > 从 python 脚本调用 ExifTool 在 Mac 中挂起,但在 Windows 中有效

问题描述

我正在使用这个答案中的脚本。我做了一个小的修改,如下所示。

修改1

sentinel = "{ready}\n"

    def __init__(self, executable="/usr/local/bin/"):
        self.executable = executable

    def __enter__(self):
        app = "exiftool"
        command_line = [app, "stay_open", "True", "-@", "-"]
        self.process = subprocess.Popen(command_line, executable=app, universal_newlines=True,
                                        stdin=subprocess.PIPE, stdout=subprocess.PIPE)
        return self

原始链接中发布的其余答案完全不变。

我把上面的调用如下,

def main():
    filename = r"/Volumes/backup/2017/MOV_0004.mp4"
    with ExifTool.ExifTool() as e:
        metadata = e.get_metadata(*filename)
    json_str = json.dumps(metadata, indent=2)
    print (json_str)

出于某种奇怪的原因,这在 Windows 上运行良好,但我无法让它在 Mac 上运行。

为了让它在 Windows 上运行,我更改了一行sentinel = "{ready}\n". 我在 Mac 上使用 python 3.7.1,在 Windows 上使用 python 3.6.1。

将不胜感激任何建议。

标签: pythonmacossubprocessexiftool

解决方案


推荐阅读