Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue #65 - Error on Windows #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions zign/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import stups_cli.config
import tokens
import yaml
import platform
from clickclick import UrlType, error, info
from requests import RequestException

Expand Down Expand Up @@ -178,18 +179,23 @@ def perform_implicit_flow(config: dict):
browser_url = urlunsplit((parsed_authorize_url.scheme, parsed_authorize_url.netloc, parsed_authorize_url.path,
param_string, ''))

# Redirect stdout and stderr. In Linux, a message is outputted to stdout when opening the browser
# (and then a message to stderr because it can't write).
saved_stdout = os.dup(1)
saved_stderr = os.dup(2)
os.close(1)
os.close(2)
os.open(os.devnull, os.O_RDWR)
try:
if platform.system() != 'Windows':
# Redirect stdout and stderr. In Linux, a message is outputted to stdout when opening the browser
# (and then a message to stderr because it can't write).
saved_stdout = os.dup(1)
saved_stderr = os.dup(2)
os.close(1)
os.close(2)
os.open(os.devnull, os.O_RDWR)
try:
webbrowser.open(browser_url, new=1, autoraise=True)
finally:
os.dup2(saved_stdout, 1)
os.dup2(saved_stderr, 2)
else:
# On Windows, the above redirections are not needed
# and cause errors in later writes to stdout
webbrowser.open(browser_url, new=1, autoraise=True)
finally:
os.dup2(saved_stdout, 1)
os.dup2(saved_stderr, 2)

info('Your browser has been opened to visit:\n\n\t{}\n'.format(browser_url))

Expand Down