Rev4203, Change console encoding to utf8 on Windows

This commit is contained in:
shortcutme 2019-09-03 12:00:25 +02:00
parent 166a65e1b1
commit 0b04176f18
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
3 changed files with 14 additions and 5 deletions

View File

@ -13,7 +13,7 @@ class Config(object):
def __init__(self, argv):
self.version = "0.7.0"
self.rev = 4200
self.rev = 4203
self.argv = argv
self.action = None
self.pending_changes = {}

View File

@ -137,14 +137,14 @@ class CryptConnectionManager:
cmd, shell=True, stderr=subprocess.STDOUT,
stdout=subprocess.PIPE, env=self.openssl_env
)
back = proc.stdout.read().strip().replace(b"\r", b"")
back = proc.stdout.read().strip().decode(errors="replace").replace("\r", "")
proc.wait()
if not (os.path.isfile(self.cacert_pem) and os.path.isfile(self.cakey_pem)):
self.log.error("RSA ECC SSL CAcert generation failed, CAcert or CAkey files not exist. (%s)" % back)
return False
else:
self.log.debug("Result: %s" % back.decode())
self.log.debug("Result: %s" % back)
# Generate certificate key and signing request
cmd_params = helper.shellquote(
@ -160,7 +160,7 @@ class CryptConnectionManager:
cmd, shell=True, stderr=subprocess.STDOUT,
stdout=subprocess.PIPE, env=self.openssl_env
)
back = proc.stdout.read().strip().decode().replace("\r", "")
back = proc.stdout.read().strip().decode(errors="replace").replace("\r", "")
proc.wait()
self.log.debug("Running: %s\n%s" % (cmd, back))
@ -179,7 +179,7 @@ class CryptConnectionManager:
cmd, shell=True, stderr=subprocess.STDOUT,
stdout=subprocess.PIPE, env=self.openssl_env
)
back = proc.stdout.read().strip().decode().replace("\r", "")
back = proc.stdout.read().strip().decode(errors="replace").replace("\r", "")
proc.wait()
self.log.debug("Running: %s\n%s" % (cmd, back))

View File

@ -76,6 +76,15 @@ if config.stack_size:
if config.msgpack_purepython:
os.environ["MSGPACK_PUREPYTHON"] = "True"
# Fix console encoding on Windows
if sys.platform.startswith("win"):
import subprocess
try:
chcp_res = subprocess.check_output("chcp 65001", shell=True).decode(errors="ignore").strip()
logging.debug("Changed console encoding to utf8: %s" % chcp_res)
except Exception as err:
logging.error("Error changing console encoding to utf8: %s" % err)
# Socket monkey patch
if config.proxy:
from util import SocksProxy