使用subprocess.Popen()时,stderr和stdout没有输出

Jer*_*ick 8 python svn subprocess

我正在使用Python来自动化SVN提交,我想将SVN命令的输出写入日志文件.我拥有的代码可以使SVN运行,但问题是在成功提交时,subprocess调用不会返回我的日志的任何输出.

当我手动运行SVN时,通过比较,我得到输出,显示命令的进度并显示正在提交的文件.这就是我想要的日志文件.SVN是否将数据输出到缓冲区而不是stdout或stderr?如何为我的日志捕获该数据?

这是我正在使用的代码:

cmd = "svn commit --non-interactive --no-auth-cache -m 'Automatic commit' ./"
process = subprocess.Popen(cmd,
                           shell=True,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE,
                           universal_newlines=True)
result = process.wait()

# Output
out = process.stdout.read()
err = process.stderr.read()
Run Code Online (Sandbox Code Playgroud)

当我运行此代码并且提交成功时,outerr变量都是空的.

jdi*_*jdi 10

wait()使用PIPE时请勿使用.使用沟通()

process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
          stderr=subprocess.PIPE, universal_newlines=True)

out, err = process.communicate()
Run Code Online (Sandbox Code Playgroud)

子流程文档:

警告
使用communic()而不是.stdin.write,.stdout.read或.stderr.read来避免由于任何其他OS管道缓冲区填满和阻止子进程而导致的死锁.