diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 20:30:15 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 20:30:15 +0000 |
commit | 333887630a7acb82cde382820650033b18532d73 (patch) | |
tree | 0524f3a857afe410887e6becef25872d975a4474 /base | |
parent | ea6e33667659f0d3fea27bd64a80a412d4b02bca (diff) | |
download | chromium_src-333887630a7acb82cde382820650033b18532d73.zip chromium_src-333887630a7acb82cde382820650033b18532d73.tar.gz chromium_src-333887630a7acb82cde382820650033b18532d73.tar.bz2 |
Harmonizing ProcessUtil::GetAppOutput on Win/Unix
BUG=None
TEST=Run the base unit-tests
Review URL: http://codereview.chromium.org/119190
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17660 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.h | 8 | ||||
-rw-r--r-- | base/process_util_unittest.cc | 17 | ||||
-rw-r--r-- | base/process_util_win.cc | 11 |
3 files changed, 13 insertions, 23 deletions
diff --git a/base/process_util.h b/base/process_util.h index 7801d4c..aaa8cbb 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -139,20 +139,12 @@ bool LaunchApp(const std::vector<std::string>& argv, bool LaunchApp(const CommandLine& cl, bool wait, bool start_hidden, ProcessHandle* process_handle); -#if defined(OS_WIN) -// Executes the application specified by |cmd_line| and copies the contents -// printed to the standard output to |output|, which should be non NULL. -// Blocks until the started process terminates. -// Returns true if the application was run successfully, false otherwise. -bool GetAppOutput(const std::wstring& cmd_line, std::string* output); -#elif defined(OS_POSIX) // Executes the application specified by |cl| and wait for it to exit. Stores // the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true // on success (application launched and exited cleanly, with exit code // indicating success). |output| is modified only when the function finished // successfully. bool GetAppOutput(const CommandLine& cl, std::string* output); -#endif // Used to filter processes by process ID. class ProcessFilter { diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 30a2c07..1e5c272 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -146,20 +146,21 @@ TEST_F(ProcessUtilTest, GetAppOutput) { .Append(FILE_PATH_LITERAL("python_24")) .Append(FILE_PATH_LITERAL("python.exe")); - // You have to put every parameter between quotes, otherwise this won't work, - // don't ask me why. - std::wstring cmd_line = L"\"" + python_runtime.value() + L"\" " + - L"\"-c\" \"import sys; sys.stdout.write('" + ASCIIToWide(message) + - L"');\""; + CommandLine cmd_line(python_runtime.value()); + cmd_line.AppendLooseValue(L"-c"); + cmd_line.AppendLooseValue(L"\"import sys; sys.stdout.write('" + + ASCIIToWide(message) + L"');\""); std::string output; ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); EXPECT_EQ(message, output); // Let's make sure stderr is ignored. - cmd_line = L"\"" + python_runtime.value() + L"\" " + - L"\"-c\" \"import sys; sys.stderr.write('Hello!');\""; + CommandLine other_cmd_line(python_runtime.value()); + other_cmd_line.AppendLooseValue(L"-c"); + other_cmd_line.AppendLooseValue( + L"\"import sys; sys.stderr.write('Hello!');\""); output.clear(); - ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); + ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); EXPECT_EQ("", output); } #endif // defined(OS_WIN) diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 8b9ede8..008cffa 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -198,12 +198,7 @@ bool KillProcessById(ProcessId process_id, int exit_code, bool wait) { return ret; } -bool GetAppOutput(const std::wstring& cmd_line, std::string* output) { - if (!output) { - NOTREACHED(); - return false; - } - +bool GetAppOutput(const CommandLine& cl, std::string* output) { HANDLE out_read = NULL; HANDLE out_write = NULL; @@ -241,7 +236,9 @@ bool GetAppOutput(const std::wstring& cmd_line, std::string* output) { start_info.dwFlags |= STARTF_USESTDHANDLES; // Create the child process. - if (!CreateProcess(NULL, const_cast<wchar_t*>(cmd_line.c_str()), NULL, NULL, + if (!CreateProcess(NULL, + const_cast<wchar_t*>(cl.command_line_string().c_str()), + NULL, NULL, TRUE, // Handles are inherited. 0, NULL, NULL, &start_info, &proc_info)) { NOTREACHED() << "Failed to start process"; |