PiotrK
PiotrK

Reputation: 99

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

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?

Upvotes: 1

Views: 6231

Answers (2)

PiotrK
PiotrK

Reputation: 99

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.

Upvotes: 5

Shweta Agarwal
Shweta Agarwal

Reputation: 1

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

Upvotes: 0

Related Questions