def _win32_popen(self, args, env, callback_trigger=None):
# This is a workaround to prevent Command Prompt windows from opening
# when spawning tahoe processes from the GUI on Windows, as Twisted's
# reactor.spawnProcess() API does not allow Windows creation flags to
# be passed to subprocesses. By passing 0x08000000 (CREATE_NO_WINDOW),
# the opening of the Command Prompt window will be surpressed while
# still allowing access to stdout/stderr. See:
# https://twistedmatrix.com/pipermail/twisted-python/2007-February/014733.html
import subprocess
proc = subprocess.Popen(
args, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True, creationflags=0x08000000)
output = BytesIO()
for line in iter(proc.stdout.readline, ''):
output.write(line.encode('utf-8'))
self.line_received(line.rstrip())
if callback_trigger and callback_trigger in line.rstrip():
return proc.pid
proc.poll()
if proc.returncode:
raise subprocess.CalledProcessError(proc.returncode, args)
else:
return output.getvalue()
评论列表
文章目录