From 2b71832f6d8dc74119589992836cf95aeb8a9842 Mon Sep 17 00:00:00 2001 From: Sergiy Byelozyorov Date: Wed, 24 Oct 2018 17:43:31 +0000 Subject: [PATCH] Hide standard output from the browser when running git-cl-web R=nodir@chromium.org Change-Id: I0816a109bc50cbc5c06339b832748f03abee372a Reviewed-on: https://chromium-review.googlesource.com/c/1296511 Commit-Queue: Sergiy Byelozyorov Reviewed-by: Nodir Turakulov --- git_cl.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/git_cl.py b/git_cl.py index 19f42b58d..547590b9f 100755 --- a/git_cl.py +++ b/git_cl.py @@ -5408,7 +5408,16 @@ def CMDweb(parser, args): print('ERROR No issue to open', file=sys.stderr) return 1 - webbrowser.open(issue_url) + # Redirect I/O before invoking browser to hide its output. For example, this + # allows to hide "Created new window in existing browser session." message + # from Chrome. Based on https://stackoverflow.com/a/2323563. + saved_stdout = os.dup(1) + os.close(1) + os.open(os.devnull, os.O_RDWR) + try: + webbrowser.open(issue_url) + finally: + os.dup2(saved_stdout, 1) return 0