From 37c70634a826cf3836bc684f97064acc3c5ab3a7 Mon Sep 17 00:00:00 2001 From: facetoe Date: Sun, 11 Jan 2015 18:56:50 +0800 Subject: [PATCH] Prevent webrowser.open() writing to stdout when opening link. --- i3pystatus/core/util.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/i3pystatus/core/util.py b/i3pystatus/core/util.py index c3b093e..098644c 100644 --- a/i3pystatus/core/util.py +++ b/i3pystatus/core/util.py @@ -439,7 +439,16 @@ def user_open(url_or_command): scheme = urlparse(url_or_command).scheme if scheme == 'http' or scheme == 'https': import webbrowser - webbrowser.open(url_or_command) + import os + # webbrowser.open() sometimes prints a message for some reason and confuses i3 + # Redirect stdout briefly to prevent this from happening. + savout = os.dup(1) + os.close(1) + os.open(os.devnull, os.O_RDWR) + try: + webbrowser.open(url_or_command) + finally: + os.dup2(savout, 1) else: import subprocess subprocess.Popen(url_or_command, shell=True)