简体   繁体   中英

SVN commands not accepted via Python subprocess module

I can enter SVN commands successfully in the Windows command line, but when I try to pass them via subprocess with shell=True I get this error:

'svn' is not recognized as an internal or external command, operable program or batch file

When I omit the shell argument I get this:

WindowsError: [Error 2] The system cannot find the file specified

I'm running Python 2.7 on Windows 10, where I also have Python 3.8 installed. I've tried a variety of SVN commands, some complex and some simple, with a variety of arguments, both as a single string and a list of strings, both in IDLE and Spyder (console and script in each), and keep getting the same results. I am able to pass other types of Windows commands via subprocess, just not SVN. I've confirmed that the COMSPEC environment variable is correct. I've also tried moving the path to svn.exe all the way up in the PATH environment variable and rebooting. No dice.

Here's an example of what I'm trying to do:

import subprocess
my_cmd = ['svn', 'propget', 'svn:externals', '-R', '"https://the/rest/of/the/url"']
res = subprocess.check_output(my_cmd, shell=True)
print "the result of the svn command via subprocess is...\n{}".format(res)

After finding that the path to svn.exe was missing from the string returned by os.environ.get('PATH') , I added this path with the following line:

os.environ['PATH'] += r"C:\Program Files\TortoiseSVN\bin;"

And now my subsequent SVN commands are working via subprocess.

Thank you @John Gordon and @Maurice Meyer for the help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM