Commit e670936f authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

[chromedriver] Support --enable-chrome-logs on Windows

On Windows, handlers are not inherited by default (unlike unix). This
includes stdout and stderr, so by default a process launched via
CreateProcess does not send output to the same place as its parent. When
running ChromeDriver manually in a terminal this is fine, since all the
output ends up in the terminal anyway, but if ChromeDriver is launched
programmatically then the root process cannot see the output from the
browser:

my_runner.exe --> chromedriver.exe --> chrome.exe

In the above example, without inherited handles my_runner.exe does not
see chrome.exe's output.

The solution is to set the stdout and stderr handles to be the same ones
that ChromeDriver is using, and make them explicitly inherited.

Bug: 1109233
Change-Id: Iac18beed5583ea7b7830015d765f3670c86b652b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335355
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798379}
parent b43fb787
...@@ -447,9 +447,9 @@ Status LaunchDesktopChrome(network::mojom::URLLoaderFactory* factory, ...@@ -447,9 +447,9 @@ Status LaunchDesktopChrome(network::mojom::URLLoaderFactory* factory,
options.new_process_group = true; options.new_process_group = true;
#endif #endif
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
#if defined(OS_POSIX) #if defined(OS_POSIX)
base::ScopedFD devnull; base::ScopedFD devnull;
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
if (!cmd_line->HasSwitch("verbose") && if (!cmd_line->HasSwitch("verbose") &&
!cmd_line->HasSwitch("enable-chrome-logs") && !cmd_line->HasSwitch("enable-chrome-logs") &&
cmd_line->GetSwitchValueASCII("log-level") != "ALL") { cmd_line->GetSwitchValueASCII("log-level") != "ALL") {
...@@ -462,6 +462,17 @@ Status LaunchDesktopChrome(network::mojom::URLLoaderFactory* factory, ...@@ -462,6 +462,17 @@ Status LaunchDesktopChrome(network::mojom::URLLoaderFactory* factory,
std::make_pair(devnull.get(), STDERR_FILENO)); std::make_pair(devnull.get(), STDERR_FILENO));
} }
#elif defined(OS_WIN) #elif defined(OS_WIN)
if (cmd_line->HasSwitch("enable-chrome-logs")) {
// On Windows, we must inherit the stdout/stderr handles, or the output from
// the browser will not be part of our output and thus not capturable by
// processes that call us.
options.stdin_handle = INVALID_HANDLE_VALUE;
options.stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
options.stderr_handle = GetStdHandle(STD_ERROR_HANDLE);
options.handles_to_inherit.push_back(options.stdout_handle);
options.handles_to_inherit.push_back(options.stderr_handle);
}
if (!SwitchToUSKeyboardLayout()) if (!SwitchToUSKeyboardLayout())
VLOG(0) << "Cannot switch to US keyboard layout - some keys may be " VLOG(0) << "Cannot switch to US keyboard layout - some keys may be "
"interpreted incorrectly"; "interpreted incorrectly";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment