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 <sergiyb@chromium.org>
Reviewed-by: Nodir Turakulov <nodir@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index 19f42b5..547590b 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -5408,7 +5408,16 @@
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