Skip to content

Commit 697be19

Browse files
committed
Redirect console output to parent process
Fixes no output when opened from a command window (e.g. --help and usage printout)
1 parent 1e408c2 commit 697be19

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

ffrunner.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,17 @@ fetch_icon(char *iconUrl, char *outPath)
664664
return false;
665665
}
666666

667+
void
668+
parent_console_redirect() {
669+
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
670+
// reopen C stdio to the attached console
671+
FILE* f;
672+
freopen_s(&f, "CONIN$", "r", stdin);
673+
freopen_s(&f, "CONOUT$", "w", stdout);
674+
freopen_s(&f, "CONOUT$", "w", stderr);
675+
}
676+
}
677+
667678
int
668679
main(int argc, char **argv)
669680
{
@@ -675,6 +686,7 @@ main(int argc, char **argv)
675686
RECT winRect;
676687
char iconFile[MAX_PATH];
677688

689+
parent_console_redirect();
678690
parse_args(argc, argv);
679691
print_args();
680692
init_logging(args.logPath, args.verboseLogging);

0 commit comments

Comments
 (0)