The filename, directory name, or volume label syntax is incorrect

可紊 提交于 2019-12-08 08:28:27

问题


I have a simple python (2.7) script that should execute few svn commands:

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])

Unfortunately when it is run on my friends machine it fails with error: "The filename, directory name, or volume label syntax is incorrect." When I run this on my machine it works fine.

If I change:

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

to

status, output = getStatusOutput(svn_cmd[0])

Then it will successfully execute first element of array (command), but then will fail on second (comment). Does anyone have any idea what can be wrong?


回答1:


Solution was easier then I thought. Problem was here:

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

and exactly [cmd] should be without [ ]. Otherwise element will be treated as a array not as string.

Hope this will help to someone.




回答2:


I have a similar code which executes fine on Linux but fails on Windows

It works if I use 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


来源:https://stackoverflow.com/questions/23623947/the-filename-directory-name-or-volume-label-syntax-is-incorrect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!