[FIX] appveyor, by adding codepage parameter

This commit is contained in:
Benedek Racz 2020-02-04 12:09:50 +01:00
parent ad50d38614
commit 7afcbe8f73
2 changed files with 15 additions and 10 deletions

View File

@ -46,6 +46,7 @@ import signal
from io import StringIO from io import StringIO
import ctypes import ctypes
from ctypes import windll
import win32console import win32console
import win32process import win32process
import win32con import win32con
@ -80,14 +81,14 @@ class ConsoleReaderBase:
This class initialize the console starts the child in it and reads the console periodically. This class initialize the console starts the child in it and reads the console periodically.
""" """
def __init__(self, path, host_pid, cp=None, window_size_x=80, window_size_y=25, def __init__(self, path, host_pid, codepage=None, window_size_x=80, window_size_y=25,
buffer_size_x=80, buffer_size_y=16000, local_echo=True, interact=False, **kwargs): buffer_size_x=80, buffer_size_y=16000, local_echo=True, interact=False, **kwargs):
"""Initialize the console starts the child in it and reads the console periodically. """Initialize the console starts the child in it and reads the console periodically.
Args: Args:
path (str): Child's executable with arguments. path (str): Child's executable with arguments.
parent_pid (int): Parent (aka. host) process process-ID parent_pid (int): Parent (aka. host) process process-ID
cp (:obj:, optional): Output console code page. codepage (:obj:, optional): Output console code page.
""" """
self.lastRead = 0 self.lastRead = 0
self.__bufferY = 0 self.__bufferY = 0
@ -109,13 +110,15 @@ class ConsoleReaderBase:
logger.info("ConsoleReader started") logger.info("ConsoleReader started")
if cp: if codepage is None:
try: codepage = windll.kernel32.GetACP()
logger.info("Setting console output code page to %s" % cp)
win32console.SetConsoleOutputCP(cp) try:
logger.info("Console output code page: %s" % ctypes.windll.kernel32.GetConsoleOutputCP()) logger.info("Setting console output code page to %s" % codepage)
except Exception as e: win32console.SetConsoleOutputCP(codepage)
logger.info(e) logger.info("Console output code page: %s" % ctypes.windll.kernel32.GetConsoleOutputCP())
except Exception as e:
logger.info(e)
try: try:
self.create_connection(**kwargs) self.create_connection(**kwargs)

View File

@ -243,6 +243,7 @@ class SpawnBase:
self.child_fd = -1 # initially closed self.child_fd = -1 # initially closed
self.timeout = timeout self.timeout = timeout
self.delimiter = EOF self.delimiter = EOF
self.codepage = codepage
self.cwd = cwd self.cwd = cwd
self.env = env self.env = env
self.echo = echo self.echo = echo
@ -362,7 +363,8 @@ class SpawnBase:
self.console_class_parameters.update({ self.console_class_parameters.update({
'host_pid': self.host_pid, 'host_pid': self.host_pid,
'local_echo': self.echo, 'local_echo': self.echo,
'interact': self.interact_state 'interact': self.interact_state,
'codepage': self.codepage
}) })
console_class_parameters_kv_pairs = [f'{k}={v}' for k,v in self.console_class_parameters.items() ] console_class_parameters_kv_pairs = [f'{k}={v}' for k,v in self.console_class_parameters.items() ]
console_class_parameters_str = ', '.join(console_class_parameters_kv_pairs) console_class_parameters_str = ', '.join(console_class_parameters_kv_pairs)