简体   繁体   English

SVN 命令不通过 Python 子进程模块接受

[英]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:我可以在 Windows 命令行中成功输入 SVN 命令,但是当我尝试通过带有 shell=True 的子进程传递它们时,我收到此错误:

'svn' is not recognized as an internal or external command, operable program or batch file 'svn' 不是内部或外部命令、可运行程序或批处理文件

When I omit the shell argument I get this:当我省略 shell 参数时,我得到这个:

WindowsError: [Error 2] The system cannot find the file specified WindowsError: [错误 2] 系统找不到指定的文件

I'm running Python 2.7 on Windows 10, where I also have Python 3.8 installed.我在 Windows 10 上运行 Python 2.7,我还安装了 Python 3.8。 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.我已经尝试了各种 SVN 命令,有些复杂,有些简单,还有各种 arguments,既作为单个字符串也作为字符串列表,在 IDLE 和 Spyder 中(每个中都有控制台和脚本),并不断获得相同的结果。 I am able to pass other types of Windows commands via subprocess, just not SVN.我能够通过子进程传递其他类型的 Windows 命令,而不是 SVN。 I've confirmed that the COMSPEC environment variable is correct.我已经确认 COMSPEC 环境变量是正确的。 I've also tried moving the path to svn.exe all the way up in the PATH environment variable and rebooting.我还尝试将 svn.exe 的路径一直移动到 PATH 环境变量中并重新启动。 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.get('PATH')返回的字符串中缺少 svn.exe 的路径后,我使用以下行添加了此路径:

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

And now my subsequent SVN commands are working via subprocess.现在我随后的 SVN 命令正在通过子进程工作。

Thank you @John Gordon and @Maurice Meyer for the help!感谢@John Gordon 和@Maurice Meyer 的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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