From 31a0ca5381f0790d30c341585b6d4ec309ca48fd Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Wed, 9 Feb 2022 05:22:13 +0800 Subject: [PATCH] allow c stdin & stderr when running in cmd.exe --- PyStand.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PyStand.cpp b/PyStand.cpp index 15a528e..ab35ddf 100644 --- a/PyStand.cpp +++ b/PyStand.cpp @@ -325,10 +325,15 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show) return 3; } if (AttachConsole(ATTACH_PARENT_PROCESS)) { -#if 0 +#ifdef _MSC_VER + freopen_s("CONOUT$", "w", stdout); + freopen_s("CONOUT$", "w", stderr); + freopen_s("CONIN$", "r", stdin); +#else freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); freopen("CONIN$", "r", stdin); +#endif int fd = fileno(stdout); if (fd >= 0) { std::string fn = std::to_string(fd); @@ -339,7 +344,6 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show) std::string fn = std::to_string(fd); SetEnvironmentVariableA("PYSTAND_STDIN", fn.c_str()); } -#endif } int hr = ps.RunString(init_script); // printf("finalize\n");