【问题标题】:Subprocess Check Output/Run Issue with current directory子进程检查当前目录的输出/运行问题
【发布时间】:2019-10-05 04:53:22
【问题描述】:

当从命令行运行它时,这是有效的

plutil -convert xml1 test.out -o outFile1.xml

在 python 2.7 中运行时出现错误:

import subprocess
subprocess.check_output(["plutil -convert xml1 test.out -o outFile1.xml"])
OSError: [Errno 2] No such file or directory

我尝试将./.\\ 添加到目录中。

我使用pwdos.getcwd() 来确保我在这两种情况下都从同一个目录运行它。

【问题讨论】:

    标签: python command-line subprocess


    【解决方案1】:

    拆分你的命令应该可以;口译员目前可能对此感到困惑。

    subprocess.check_output(["/usr/bin/plutil", "-convert", "xml1", "test", "-o", "outFile1.xml"])
    

    此外,您可能希望使用plutil 的绝对路径(可选)。

    【讨论】:

    • 为什么一定要拆分?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 2022-10-14
    • 1970-01-01
    • 2017-07-22
    • 2013-06-26
    相关资源
    最近更新 更多