Chromium Code Reviews| Index: test/win/child_launcher.cc |
| diff --git a/test/win/child_launcher.cc b/test/win/child_launcher.cc |
| index cc95255c58d59c9393e7be72412e7794717b4fae..31c4bf75f677f5878241fd98f6895e4c4f322713 100644 |
| --- a/test/win/child_launcher.cc |
| +++ b/test/win/child_launcher.cc |
| @@ -25,12 +25,13 @@ ChildLauncher::ChildLauncher(const std::wstring& executable, |
| command_line_(command_line), |
| process_handle_(), |
| main_thread_handle_(), |
| - stdout_read_handle_() { |
| + stdout_read_handle_(), |
| + stdin_write_handle_() { |
| } |
| ChildLauncher::~ChildLauncher() { |
| - EXPECT_EQ(WAIT_OBJECT_0, |
| - WaitForSingleObject(process_handle_.get(), INFINITE)); |
| + if (process_handle_.is_valid()) |
| + WaitForExit(); |
| } |
| void ChildLauncher::Start() { |
| @@ -38,10 +39,11 @@ void ChildLauncher::Start() { |
| ASSERT_FALSE(main_thread_handle_.is_valid()); |
| ASSERT_FALSE(stdout_read_handle_.is_valid()); |
| - // Create a pipe for the stdout of the child. |
| + // Create a pipe for the stdin/stdout of the child. |
|
Mark Mentovai
2015/09/22 13:17:29
Now this is plural “pipes.”
scottmg
2015/09/22 17:26:00
Done.
|
| SECURITY_ATTRIBUTES security_attributes = {0}; |
| security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES); |
| security_attributes.bInheritHandle = true; |
| + |
| HANDLE stdout_read; |
| HANDLE stdout_write; |
| ASSERT_TRUE(CreatePipe(&stdout_read, &stdout_write, &security_attributes, 0)); |
| @@ -50,9 +52,17 @@ void ChildLauncher::Start() { |
| ASSERT_TRUE( |
| SetHandleInformation(stdout_read_handle_.get(), HANDLE_FLAG_INHERIT, 0)); |
| + HANDLE stdin_read; |
| + HANDLE stdin_write; |
| + ASSERT_TRUE(CreatePipe(&stdin_read, &stdin_write, &security_attributes, 0)); |
| + stdin_write_handle_.reset(stdin_write); |
| + ScopedFileHANDLE read_handle(stdin_read); |
| + ASSERT_TRUE( |
| + SetHandleInformation(stdin_write_handle_.get(), HANDLE_FLAG_INHERIT, 0)); |
| + |
| STARTUPINFO startup_info = {0}; |
| startup_info.cb = sizeof(startup_info); |
| - startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); |
| + startup_info.hStdInput = read_handle.get(); |
| startup_info.hStdOutput = write_handle.get(); |
| startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); |
| startup_info.dwFlags = STARTF_USESTDHANDLES; |
| @@ -76,6 +86,16 @@ void ChildLauncher::Start() { |
| process_handle_.reset(process_information.hProcess); |
| } |
| +DWORD ChildLauncher::WaitForExit() { |
| + EXPECT_TRUE(process_handle_.is_valid()); |
| + EXPECT_EQ(WAIT_OBJECT_0, |
| + WaitForSingleObject(process_handle_.get(), INFINITE)); |
| + DWORD exit_code; |
|
Mark Mentovai
2015/09/22 13:17:29
Initialize this so that if GetExitCodeProcess() fa
scottmg
2015/09/22 17:25:59
Done.
|
| + EXPECT_TRUE(GetExitCodeProcess(process_handle_.get(), &exit_code)); |
| + process_handle_.reset(); |
| + return exit_code; |
| +} |
| + |
| // Ref: http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx |
| void AppendCommandLineArgument(const std::wstring& argument, |
| std::wstring* command_line) { |