mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
deploy-ng: fix redirecting GUI app output to log in VC2015/UCRT
Fixes #461
This commit is contained in:
parent
3124564040
commit
2664a24e6a
@ -264,17 +264,29 @@ static int setup_logging(const char *path, int append) {
|
||||
SetFilePointer(handle, 0, NULL, FILE_END);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
int fd = _open_osfhandle((intptr_t)handle, _O_WRONLY | _O_TEXT | (append ? _O_APPEND : 0));
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, handle);
|
||||
_dup2(fd, 1);
|
||||
|
||||
SetStdHandle(STD_ERROR_HANDLE, handle);
|
||||
_dup2(fd, 2);
|
||||
|
||||
// If we are running under the UCRT in a GUI application, we can't be sure
|
||||
// that we have valid fds for stdout and stderr, so we have to set them up.
|
||||
// One way to do this is to reopen them to something silly (like NUL).
|
||||
if (_fileno(stdout) < 0) {
|
||||
_close(1);
|
||||
_wfreopen(L"\\\\.\\NUL", L"w", stdout);
|
||||
}
|
||||
|
||||
if (_fileno(stderr) < 0) {
|
||||
_close(2);
|
||||
_wfreopen(L"\\\\.\\NUL", L"w", stderr);
|
||||
}
|
||||
|
||||
// Now replace the stdout and stderr file descriptors with one pointing to
|
||||
// our desired handle.
|
||||
int fd = _open_osfhandle((intptr_t)handle, _O_WRONLY | _O_TEXT | (append ? _O_APPEND : 0));
|
||||
_dup2(fd, _fileno(stdout));
|
||||
_dup2(fd, _fileno(stderr));
|
||||
_close(fd);
|
||||
|
||||
return 1;
|
||||
#else
|
||||
// Does it start with a tilde? Perform tilde expansion if so.
|
||||
|
Loading…
x
Reference in New Issue
Block a user