mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-02 03:06:43 +00:00
Merge branch 'redirection-fix' into 'master'
Only reroute stdout etc. to new console if not already redirected Closes #5650 See merge request OpenMW/openmw!408
This commit is contained in:
commit
37e81f0df8
1 changed files with 26 additions and 6 deletions
|
@ -11,11 +11,22 @@
|
||||||
namespace Debug
|
namespace Debug
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
bool isRedirected(DWORD nStdHandle)
|
||||||
|
{
|
||||||
|
DWORD fileType = GetFileType(GetStdHandle(nStdHandle));
|
||||||
|
|
||||||
|
return (fileType == FILE_TYPE_DISK) || (fileType == FILE_TYPE_PIPE);
|
||||||
|
}
|
||||||
|
|
||||||
bool attachParentConsole()
|
bool attachParentConsole()
|
||||||
{
|
{
|
||||||
if (GetConsoleWindow() != nullptr)
|
if (GetConsoleWindow() != nullptr)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
bool inRedirected = isRedirected(STD_INPUT_HANDLE);
|
||||||
|
bool outRedirected = isRedirected(STD_OUTPUT_HANDLE);
|
||||||
|
bool errRedirected = isRedirected(STD_ERROR_HANDLE);
|
||||||
|
|
||||||
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||||
{
|
{
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -24,12 +35,21 @@ namespace Debug
|
||||||
std::cerr.flush();
|
std::cerr.flush();
|
||||||
|
|
||||||
// this looks dubious but is really the right way
|
// this looks dubious but is really the right way
|
||||||
_wfreopen(L"CON", L"w", stdout);
|
if (!inRedirected)
|
||||||
_wfreopen(L"CON", L"w", stderr);
|
{
|
||||||
_wfreopen(L"CON", L"r", stdin);
|
_wfreopen(L"CON", L"r", stdin);
|
||||||
freopen("CON", "w", stdout);
|
freopen("CON", "r", stdin);
|
||||||
freopen("CON", "w", stderr);
|
}
|
||||||
freopen("CON", "r", stdin);
|
if (!outRedirected)
|
||||||
|
{
|
||||||
|
_wfreopen(L"CON", L"w", stdout);
|
||||||
|
freopen("CON", "w", stdout);
|
||||||
|
}
|
||||||
|
if (!errRedirected)
|
||||||
|
{
|
||||||
|
_wfreopen(L"CON", L"w", stderr);
|
||||||
|
freopen("CON", "w", stderr);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue