Skip to content

Commit e96253d

Browse files
committed
使用subprocess.Popen()
1 parent b35303c commit e96253d

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

subprocess_git.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,49 @@
1515
print type(retcode)
1616
print "---------------------"
1717

18-
# 切换路径
19-
dir = "/home/wmm/studydata"
20-
os.chdir(dir)
21-
print os.getcwd()
18+
# 写入文件
19+
filename = 'log.txt'
20+
file_object = open(filename, 'wb+')
2221

2322
bash = "git"
2423
active = "push"
2524
option = "test"
2625
branch = "master"
27-
# url = "git@github.com:PythonObject/python_base_subprocess_test_repository.git"
28-
retcode = subprocess.call([bash, active, option, branch])
29-
print retcode
26+
27+
# 切换路径
28+
dir = "/home/wmm/studydata"
29+
os.chdir(dir)
30+
print os.getcwd()
31+
32+
active = "clone "
33+
para = "--bare"
34+
url = "git@github.com:PythonObject/python_base_subprocess_test_repository.git"
35+
# command = format("" + bash +' ' + '' + url)
36+
command = "git clone git@github.com:PythonObject/python_base_subprocess_test_repository.git"
37+
print command
38+
# subprocess.call(bash, None, para, active, url)
39+
result = subprocess.Popen(
40+
args=command,
41+
shell=True,
42+
stdin=None,
43+
stdout=file_object,
44+
stderr=file_object,
45+
).wait()
46+
print result
47+
print type(result)
48+
49+
file_object.seek(0)
50+
contents = file_object.read()
51+
file_object.close()
52+
print contents
53+
54+
# 直接push到另一个remote
55+
# bash = "git"
56+
# active = "push"
57+
# option = "test"
58+
# branch = "master"
59+
# # url = "git@github.com:PythonObject/python_base_subprocess_test_repository.git"
60+
# retcode = subprocess.call([bash, active, option, branch])
61+
# print retcode
62+
3063

0 commit comments

Comments
 (0)