summaryrefslogtreecommitdiff
path: root/src/porting.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/porting.cpp')
-rw-r--r--src/porting.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/porting.cpp b/src/porting.cpp
index 4786a2a39..9d859da7d 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -929,4 +929,18 @@ bool secure_rand_fill_buf(void *buf, size_t len)
#endif
+void attachOrCreateConsole(void)
+{
+#ifdef _WIN32
+ static bool consoleAllocated = false;
+ const bool redirected = (_fileno(stdout) == -2 || _fileno(stdout) == -1); // If output is redirected to e.g a file
+ if (!consoleAllocated && redirected && (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())) {
+ freopen("CONOUT$", "w", stdout);
+ freopen("CONOUT$", "w", stderr);
+ consoleAllocated = true;
+ }
+#endif
+}
+
+
} //namespace porting