![](/img/trans.png)
[英]Error in cloning repo from git with subprocess python 3.8 on windows
[英]Cloning a git repo from git bash using python script from command prompt failing. Why?
git bash 突然关闭而不克隆 repo。 我无法理解这里有什么问题。
import os
import subprocess
parent_dir = r'C:\Users\user\Documents'
dir_name = 'Git_temp'
dir_path = os.path.join(parent_dir, dir_name)
os.mkdir(dir_path)
print("{0} created under {1}".format(dir_name, parent_dir))
os.chdir(dir_path)
print("Current Working Directory : {0}".format(os.getcwd()))
git_file = "C:\Program Files\Git\git-bash.exe"
git_clone_cmd = "git clone https://github.com/patankar-saransh/test_repo.git"
subprocess.Popen([git_file, git_clone_cmd])
如果你不想使用GitPython ,那么只需确保git.exe
在你的%PATH%
中。
那么您的电话将是:
import subprocess
process = subprocess.Popen(["git", "clone", "https://..."], stdout=subprocess.PIPE)
output = process.communicate()[0]
如此处所示,使用 Python 2.7+,使用check_output
import subprocess
output = subprocess.check_output(["git", "clone", "https://..."]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.