Prevent webrowser.open() writing to stdout when opening link.
This commit is contained in:
parent
05349256de
commit
37c70634a8
@ -439,7 +439,16 @@ def user_open(url_or_command):
|
|||||||
scheme = urlparse(url_or_command).scheme
|
scheme = urlparse(url_or_command).scheme
|
||||||
if scheme == 'http' or scheme == 'https':
|
if scheme == 'http' or scheme == 'https':
|
||||||
import webbrowser
|
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:
|
else:
|
||||||
import subprocess
|
import subprocess
|
||||||
subprocess.Popen(url_or_command, shell=True)
|
subprocess.Popen(url_or_command, shell=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user