Add ICU message format support
[chromium-blink-merge.git] / chromecast / base / process_utils.cc
blob9e379a05f52c67c96e027230c715c908bb220ad1
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/base/process_utils.h"
7 #include <errno.h>
8 #include <stdio.h>
10 #include "base/logging.h"
11 #include "base/posix/safe_strerror.h"
12 #include "base/strings/string_util.h"
14 namespace chromecast {
16 bool GetAppOutput(const std::vector<std::string>& argv, std::string* output) {
17 DCHECK(output);
19 // Join the args into one string, creating the command.
20 std::string command = base::JoinString(argv, " ");
22 // Open the process.
23 FILE* fp = popen(command.c_str(), "r");
24 if (!fp) {
25 LOG(ERROR) << "popen (" << command << ") failed: "
26 << base::safe_strerror(errno);
27 return false;
30 // Fill |output| with the stdout from the process.
31 output->clear();
32 while (!feof(fp)) {
33 char buffer[256];
34 size_t bytes_read = fread(buffer, 1, sizeof(buffer), fp);
35 if (bytes_read <= 0)
36 break;
37 output->append(buffer, bytes_read);
40 // pclose() function waits for the associated process to terminate and returns
41 // the exit status.
42 return (pclose(fp) == 0);
45 } // namespace chromecast