问题
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