Commit d7f5ee8b authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Add stdin_handle and stdout_handle in base::LaunchOptions.

New members in LaunchOptions will allow to redirect stdin and stdout on
Windows.

This change was originally implemented by eaugusti@chromium.com in
crrev.com/10918255 .

BUG=142915


Review URL: https://chromiumcodereview.appspot.com/11419267

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175268 0039d316-1c4b-4281-b951-d872f2087c98
parent ccecfd31
......@@ -240,6 +240,9 @@ struct LaunchOptions {
#if defined(OS_WIN)
start_hidden(false), inherit_handles(false), as_user(NULL),
empty_desktop_name(false), job_handle(NULL),
stdin_handle(NULL),
stdout_handle(NULL),
stderr_handle(NULL),
force_breakaway_from_job_(false)
#else
environ(NULL), fds_to_remap(NULL), maximize_rlimits(NULL),
......@@ -262,7 +265,10 @@ struct LaunchOptions {
#if defined(OS_WIN)
bool start_hidden;
// If true, the new process inherits handles from the parent.
// If true, the new process inherits handles from the parent. In production
// code this flag should be used only when running short-lived, trusted
// binaries, because open handles from other libraries and subsystems will
// leak to the child process, causing errors such as open socket hangs.
bool inherit_handles;
// If non-NULL, runs as if the user represented by the token had launched it.
......@@ -282,6 +288,14 @@ struct LaunchOptions {
// the job object fails.
HANDLE job_handle;
// Handles for the redirection of stdin, stdout and stderr. The handles must
// be inheritable. Caller should either set all three of them or none (i.e.
// there is no way to redirect stderr without redirecting stdin). The
// |inherit_handles| flag must be set to true when redirecting stdio stream.
HANDLE stdin_handle;
HANDLE stdout_handle;
HANDLE stderr_handle;
// If set to true, ensures that the child process is launched with the
// CREATE_BREAKAWAY_FROM_JOB flag which allows it to breakout of the parent
// job if any.
......
......@@ -293,6 +293,17 @@ bool LaunchProcess(const string16& cmdline,
startup_info.dwFlags = STARTF_USESHOWWINDOW;
startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW;
if (options.stdin_handle || options.stdout_handle || options.stderr_handle) {
DCHECK(options.inherit_handles);
DCHECK(options.stdin_handle);
DCHECK(options.stdout_handle);
DCHECK(options.stderr_handle);
startup_info.dwFlags |= STARTF_USESTDHANDLES;
startup_info.hStdInput = options.stdin_handle;
startup_info.hStdOutput = options.stdout_handle;
startup_info.hStdError = options.stderr_handle;
}
DWORD flags = 0;
if (options.job_handle) {
......
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