Bug 787313 - Add /attach-console argument on Windows in order to attach Firefox std IO to parent console. r=ted

This commit is contained in:
Alexandre Poirot 2012-09-25 12:58:08 -04:00
parent afd4f0c71e
commit cc7725aed0

View File

@ -332,22 +332,6 @@ NS_IMPL_RELEASE_INHERITED(nsNativeAppSupportWin, nsNativeAppSupportBase)
void void
nsNativeAppSupportWin::CheckConsole() { nsNativeAppSupportWin::CheckConsole() {
// Try to attach console to the parent process.
// It will succeed when the parent process is a command line,
// so that stdio will be displayed in it.
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
// Change std handles to refer to new console handles. Before doing so,
// ensure that stdout/stderr haven't been redirected to a valid file
if (_fileno(stdout) == -1 || _get_osfhandle(fileno(stdout)) == -1)
freopen("CONOUT$", "w", stdout);
// There isn't any `CONERR$`, so that we merge stderr into CONOUT$
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx
if (_fileno(stderr) == -1 || _get_osfhandle(fileno(stderr)) == -1)
freopen("CONOUT$", "w", stderr);
if (_fileno(stdin) == -1 || _get_osfhandle(fileno(stdin)) == -1)
freopen("CONIN$", "r", stdin);
}
for ( int i = 1; i < gArgc; i++ ) { for ( int i = 1; i < gArgc; i++ ) {
if ( strcmp( "-console", gArgv[i] ) == 0 if ( strcmp( "-console", gArgv[i] ) == 0
|| ||
@ -408,8 +392,25 @@ nsNativeAppSupportWin::CheckConsole() {
--gArgc; --gArgc;
// Don't bother doing this more than once. } else if ( strcmp( "-attach-console", gArgv[i] ) == 0
break; ||
strcmp( "/attach-console", gArgv[i] ) == 0 ) {
// Try to attach console to the parent process.
// It will succeed when the parent process is a command line,
// so that stdio will be displayed in it.
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
// Change std handles to refer to new console handles.
// Before doing so, ensure that stdout/stderr haven't been
// redirected to a valid file
if (_fileno(stdout) == -1 ||
_get_osfhandle(fileno(stdout)) == -1)
freopen("CONOUT$", "w", stdout);
if (_fileno(stderr) == -1 ||
_get_osfhandle(fileno(stderr)) == -1)
freopen("CONERR$", "w", stderr);
if (_fileno(stdin) == -1 || _get_osfhandle(fileno(stdin)) == -1)
freopen("CONIN$", "r", stdin);
}
} }
} }