Surpressing stdout/stderr from opening web browsers
This commit is contained in:
@@ -4,6 +4,6 @@ kitchen==1.2.4
|
||||
mailcap-fix==0.1.3
|
||||
requests==2.11.0
|
||||
six==1.10.0
|
||||
pytest==3.0.7
|
||||
pytest==3.2.3
|
||||
vcrpy==1.10.5
|
||||
pylint==1.6.5
|
||||
@@ -513,9 +513,21 @@ class Terminal(object):
|
||||
# can re-use the webbrowser instance that has been patched
|
||||
# by RTV. It's also safer because it doesn't inject
|
||||
# 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
|
||||
# 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.start()
|
||||
|
||||
Reference in New Issue
Block a user