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"
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
) {
19 // Join the args into one string, creating the command.
20 std::string command
= base::JoinString(argv
, " ");
23 FILE* fp
= popen(command
.c_str(), "r");
25 LOG(ERROR
) << "popen (" << command
<< ") failed: "
26 << base::safe_strerror(errno
);
30 // Fill |output| with the stdout from the process.
34 size_t bytes_read
= fread(buffer
, 1, sizeof(buffer
), fp
);
37 output
->append(buffer
, bytes_read
);
40 // pclose() function waits for the associated process to terminate and returns
42 return (pclose(fp
) == 0);
45 } // namespace chromecast