Allow the --version argument to be used when running updater.exe from a console under Windows

Attach to the parent process's console and re-open stdout/stderr
before attempting to print the version number.
This commit is contained in:
Robert Knight 2011-09-27 16:35:20 +01:00
parent c9543e59f6
commit 60357cada9
1 changed files with 12 additions and 0 deletions

View File

@ -86,6 +86,17 @@ bool unpackBundle(int argc, char** argv)
} }
#endif #endif
void setupConsole()
{
#ifdef PLATFORM_WINDOWS
// see http://stackoverflow.com/questions/587767/how-to-output-to-console-in-c-windows
// and http://www.libsdl.org/cgi/docwiki.cgi/FAQ_Console
AttachConsole(ATTACH_PARENT_PROCESS);
freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );
#endif
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
#ifdef PLATFORM_MAC #ifdef PLATFORM_MAC
@ -108,6 +119,7 @@ int main(int argc, char** argv)
options.parse(argc,argv); options.parse(argc,argv);
if (options.showVersion) if (options.showVersion)
{ {
setupConsole();
std::cout << "Update installer version " << UPDATER_VERSION << std::endl; std::cout << "Update installer version " << UPDATER_VERSION << std::endl;
return 0; return 0;
} }