fixed console output not working under Windows

This commit is contained in:
Thomas Jentzsch 2022-07-07 20:25:30 +02:00
parent b8527cd5ef
commit a1f6194c53
1 changed files with 26 additions and 1 deletions

View File

@ -153,6 +153,26 @@ bool isProfilingRun(int ac, char* av[]) {
return string(av[1]) == "-profile";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void attachConsole()
{
#if defined(BSPF_WINDOWS)
// Attach console to allow command line output (e.g. for -help)
AttachConsole(ATTACH_PARENT_PROCESS);
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void freeConsole()
{
#if defined(BSPF_WINDOWS)
cout << "Press \"Control + C\"" << std::flush;
FreeConsole();
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#if defined(BSPF_MACOS)
int stellaMain(int ac, char* av[])
@ -219,22 +239,27 @@ int main(int ac, char* av[])
string romfile = localOpts["ROMFILE"].toString();
if(localOpts["listrominfo"].toBool())
{
attachConsole();
Logger::debug("Showing output from 'listrominfo' ...");
theOSystem->propSet().print();
freeConsole();
return Cleanup();
}
else if(localOpts["rominfo"].toBool())
{
attachConsole();
Logger::debug("Showing output from 'rominfo' ...");
FSNode romnode(romfile);
Logger::error(theOSystem->getROMInfo(romnode));
freeConsole();
return Cleanup();
}
else if(localOpts["help"].toBool())
{
attachConsole();
Logger::debug("Displaying usage");
theOSystem->settings().usage();
freeConsole();
return Cleanup();
}