| Index: base/process_util_win.cc
|
| diff --git a/base/process_util_win.cc b/base/process_util_win.cc
|
| index 3ac2ca4de7ba88ef635a755303d56f10392f1344..6cbc887fb5277d9d773fdc6426474d70fa0b49a5 100644
|
| --- a/base/process_util_win.cc
|
| +++ b/base/process_util_win.cc
|
| @@ -122,6 +122,24 @@ void TimerExpiredTask::KillProcess() {
|
| } // namespace
|
|
|
| void RouteStdioToConsole() {
|
| + // Don't change anything if stdout or stderr already point to a
|
| + // valid stream.
|
| + //
|
| + // If we are running under Buildbot or under Cygwin's default
|
| + // terminal (mintty), stderr and stderr will be pipe handles. In
|
| + // that case, we don't want to open CONOUT$, because its output
|
| + // likely does not go anywhere.
|
| + //
|
| + // We don't use GetStdHandle() to check stdout/stderr here because
|
| + // it can return dangling IDs of handles that were never inherited
|
| + // by this process. These IDs could have been reused by the time
|
| + // this function is called. The CRT checks the validity of
|
| + // stdout/stderr on startup (before the handle IDs can be reused).
|
| + // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was
|
| + // invalid.
|
| + if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0)
|
| + return;
|
| +
|
| if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
|
| unsigned int result = GetLastError();
|
| // Was probably already attached.
|
|
|