我有以下代码:
pwd = '/home/user/svnexport/Repo/'
updateSVN = "svn up " + pwd
cmd = os.popen(updateSVN)
getAllInfo = "svn info " + pwd + "branches/* " + pwd + "tags/* " + pwd + "trunk/*"
cmd = os.popen(getAllInfo)
在
cmd = os.popen(updateSVN)
开始执行之前,如何确定cmd = os.popen(getAllInfo)
已经完成执行?
最佳答案
您应该使用subprocess
:
import subprocess
import glob
pwd = '/home/user/svnexport/Repo/'
updateSVN = ["svn", "up", pwd]
cmd = subprocess.Popen(updateSVN)
status = cmd.wait()
# the same can be achieved in a shorter way:
filelists = [glob.glob(pwd + i + "/*") for i in ('branches', 'tags', 'trunk')]
filelist = sum(filelists, []) # add them together
getAllInfo = ["svn", "info"] + filelist
status = subprocess.call(getAllInfo)
如果您需要捕获子流程的输出,请执行
process = subprocess.Popen(..., stdout=subprocess.PIPE)
data = process.stdout.read()
status = subprocess.wait()
关于python - Python os.popen : How to ensure popen(…) has completed execution before continuing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21414575/