From a237c5e0d5c09aa8232cbe314fac14f517c0e84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Mon, 6 May 2024 19:37:31 +0800 Subject: [PATCH] fix --- plugins/exec/PyStand.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/exec/PyStand.cpp b/plugins/exec/PyStand.cpp index 53f15623..fffad6a9 100644 --- a/plugins/exec/PyStand.cpp +++ b/plugins/exec/PyStand.cpp @@ -266,7 +266,19 @@ const auto init_script = L" ctypes.windll.user32.MessageBoxW(None, str(msg), str(info), 0)\n" L" return 0\n" L"os.MessageBox = MessageBox\n" - +#ifndef PYSTAND_CONSOLE + L"try:\n" + L" fd = os.open('CONOUT$', os.O_RDWR | os.O_BINARY, encoding='utf8')\n" + L" fp = os.fdopen(fd, 'w', encoding='utf8')\n" + L" sys.stdout = fp\n" + L" sys.stderr = fp\n" + L" attached = True\n" + L"except Exception as e:\n" + L" fp = open(os.devnull, 'w', encoding='utf8')\n" + L" sys.stdout = fp\n" + L" sys.stderr = fp\n" + L" attached = False\n" +#endif L"sys.argv = [os.environ['LUNA_EXE_NAME'] ,sys.argv[0], PYSTAND_SCRIPT] + sys.argv[1:]\n" L"text = open(PYSTAND_SCRIPT, 'rb').read()\n" L"environ = {'__file__': PYSTAND_SCRIPT, '__name__': '__main__'}\n" @@ -276,6 +288,8 @@ const auto init_script = L" code = compile(text, PYSTAND_SCRIPT, 'exec')\n" L" exec(code, environ)\n" L"except Exception:\n" + L" if attached:\n" + L" raise\n" L" import traceback, io\n" L" sio = io.StringIO()\n" L" traceback.print_exc(file = sio)\n"