Python无法找到写入输出的文件路径

时间:2014-11-07 06:22:03

标签: python

我在Python中有以下静态方法。

import subprocess   

class ProcessUtility:

    @staticmethod
    def execute_command(url):
        process = None
        process = subprocess.check_output(["phantomas " + url  + " --har=test.har"])
        return process

它命令基本上将输出写入test.har文件。我已经在与脚本相同的目录中创建了test.har文件,并赋予它读,写和执行权限。

执行后我收到错误。

OSError: [Errno 2] No such file or directory

任何想法,为什么我一直这样。

1 个答案:

答案 0 :(得分:2)

如果subprocess(默认值),则大多数shell=False函数采用参数列表而不是字符串。试试

process = subprocess.check_output(['phantomas', url, '--har=test.har'])