Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / chromecast / base / process_utils.cc
blob901d53d764d9edcadbf1dcaae7aa1b23cfe2d3c4
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/safe_strerror_posix.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 = JoinString(argv, ' ');
22 // Open the process.
23 FILE* fp = popen(command.c_str(), "r");
24 if (!fp) {
25 LOG(ERROR) << "popen (" << command << ") failed: " << safe_strerror(errno);
26 return false;
29 // Fill |output| with the stdout from the process.
30 output->clear();
31 while (!feof(fp)) {
32 char buffer[256];
33 size_t bytes_read = fread(buffer, 1, sizeof(buffer), fp);
34 if (bytes_read <= 0)
35 break;
36 output->append(buffer, bytes_read);
39 // pclose() function waits for the associated process to terminate and returns
40 // the exit status.
41 return (pclose(fp) == 0);
44 } // namespace chromecast