Surpressing stdout/stderr from opening web browsers

This commit is contained in:
Michael Lazar
2017-11-10 19:56:17 -05:00
parent 78625fddee
commit 1e18c87757
2 changed files with 16 additions and 4 deletions

View File

@@ -4,6 +4,6 @@ kitchen==1.2.4
mailcap-fix==0.1.3 mailcap-fix==0.1.3
requests==2.11.0 requests==2.11.0
six==1.10.0 six==1.10.0
pytest==3.0.7 pytest==3.2.3
vcrpy==1.10.5 vcrpy==1.10.5
pylint==1.6.5 pylint==1.6.5

View File

@@ -513,9 +513,21 @@ class Terminal(object):
# can re-use the webbrowser instance that has been patched # can re-use the webbrowser instance that has been patched
# by RTV. It's also safer because it doesn't inject # by RTV. It's also safer because it doesn't inject
# python code through the command line. # python code through the command line.
null = open(os.devnull, 'ab+', 0)
sys.stdout, sys.stderr = null, null # Surpress stdout/stderr from the browser, see
webbrowser.open_new_tab(url) # https://stackoverflow.com/questions/2323080. We can't
# depend on replacing sys.stdout & sys.stderr because
# webbrowser uses Popen().
stdout, stderr = os.dup(1), os.dup(2)
null = os.open(os.devnull, os.O_RDWR)
try:
os.dup2(null, 1)
os.dup2(null, 2)
webbrowser.open_new_tab(url)
finally:
null.close()
os.dup2(stdout, 1)
os.dup2(stderr, 2)
p = Process(target=open_url_silent, args=(url,)) p = Process(target=open_url_silent, args=(url,))
p.start() p.start()