Skip to content

Commit 164a7b9

Browse files
author
skywind3000
committed
fixed: issues in stdout/stderr attaching
1 parent 31a0ca5 commit 164a7b9

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

PyStand.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
// Last Modified: 2022/02/03 23:39:54
77
//
88
//=====================================================================
9+
#ifdef _MSC_VER
10+
#define _CRT_SECURE_NO_WARNINGS 1
11+
#endif
12+
913
#include "PyStand.h"
1014
#include <shlwapi.h>
1115
#include <string>
@@ -325,21 +329,14 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
325329
return 3;
326330
}
327331
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
328-
#ifdef _MSC_VER
329-
freopen_s("CONOUT$", "w", stdout);
330-
freopen_s("CONOUT$", "w", stderr);
331-
freopen_s("CONIN$", "r", stdin);
332-
#else
333332
freopen("CONOUT$", "w", stdout);
334333
freopen("CONOUT$", "w", stderr);
335-
freopen("CONIN$", "r", stdin);
336-
#endif
337-
int fd = fileno(stdout);
334+
int fd = _fileno(stdout);
338335
if (fd >= 0) {
339336
std::string fn = std::to_string(fd);
340337
SetEnvironmentVariableA("PYSTAND_STDOUT", fn.c_str());
341338
}
342-
fd = fileno(stdin);
339+
fd = _fileno(stdin);
343340
if (fd >= 0) {
344341
std::string fn = std::to_string(fd);
345342
SetEnvironmentVariableA("PYSTAND_STDIN", fn.c_str());

0 commit comments

Comments
 (0)