#include "chromecast/base/process_utils.h"
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/posix/safe_strerror.h"
#include "base/strings/string_util.h"
namespace chromecast {
bool GetAppOutput(const std::vector<std::string>& argv, std::string* output) {
DCHECK(output);
std::string command = base::JoinString(argv, " ");
FILE* fp = popen(command.c_str(), "r");
if (!fp) {
PLOG(ERROR) << "popen (" << command << ") failed";
return false;
}
output->clear();
while (!feof(fp)) {
char buffer[256];
size_t bytes_read = UNSAFE_TODO(fread(buffer, 1, sizeof(buffer), fp));
if (bytes_read <= 0)
break;
output->append(buffer, bytes_read);
}
return (pclose(fp) == 0);
}
}