main: keep a redirected stdout on Windows instead of opening a console

With -no-ui, -cli, -tui or -stdout the process always called AllocConsole and
reopened stdout onto it, so a parent capturing the output through a pipe got
nothing and a console window popped up beside it. Skip the console when the
standard output handle is already a pipe or a file.
This commit is contained in:
Rix
2026-10-10 11:34:53 -07:00
parent 4ab5ce3945
commit 45563dbfd8
+5 -1
View File
@@ -239,7 +239,11 @@ int pcsxMain(int argc, char **argv) {
#if defined(_WIN32) || defined(_WIN64)
if (args.get<bool>("stdout") || args.get<bool>("no-ui") || args.get<bool>("cli") || args.get<bool>("tui")) {
if (AllocConsole()) {
// A parent that captures our output hands us a pipe or a file; keep it
// instead of opening a console window nobody reads.
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
bool redirected = out && out != INVALID_HANDLE_VALUE && GetFileType(out) != FILE_TYPE_UNKNOWN;
if (!redirected && AllocConsole()) {
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);