【问题标题】:The filename, directory name, or volume label syntax is incorrect文件名、目录名或卷标语法不正确
【发布时间】:2014-06-30 16:42:18
【问题描述】:

我有一个简单的 python (2.7) 脚本,应该执行一些 svn 命令:

def getStatusOutput(cmd):
    print cmd
    p = subprocess.Popen([cmd],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    output, status = p.communicate()
    return status, output

svn_cmd = [
        ["svn co " + FIRMWARE_URL + "/branches/interfaces/ interfaces --depth empty", ""],
        ["svn up interfaces/actual_ver.txt", "  Getting current version of a branch "]
        ]
status, output = getStatusOutput(svn_cmd[0][0])

不幸的是,当它在我朋友的机器上运行时失败并出现错误:“文件名、目录名或卷标语法不正确。” 当我在我的机器上运行它时,它工作正常。

如果我改变:

status, output = getStatusOutput(svn_cmd[0][0])

到

status, output = getStatusOutput(svn_cmd[0])

然后它将成功执行数组的第一个元素(命令),但随后将失败第二个(注释)。有谁知道可能出了什么问题?

【问题讨论】:

    标签: python svn out


    【解决方案1】:

    解决方案比我想象的要容易。问题出在这里:

    p = subprocess.Popen([cmd],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    

    而 [cmd] 应该没有 [ ]。否则元素将被视为数组而不是字符串。

    希望这对某人有所帮助。

    【讨论】:

      【解决方案2】:

      我有一个类似的代码,在 Linux 上运行良好,但在 Windows 上失败

      如果我使用 shlex.split() 就可以了

      import shlex
      CMD="your command"
      cmdList=shlex.split(CMD)
      proc = subprocess.Popen(cmdList,stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True
      (out, err) = proc.communicate()
      print err
      

      【讨论】:

        猜你喜欢
        • 2019-05-24
        • 2019-09-30
        • 2018-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        相关资源
        最近更新 更多