blob: 4bcbcac42f5ea3156f33cdac2d40b69ac276571e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/*
* Utility routines.
*
* Licensed under GPLv2 or later, see file COPYING in this tarball for details.
*/
#include "abrtlib.h"
using namespace std;
string popen_and_save_output(const char *cmd)
{
string result;
FILE *fp = popen(cmd, "r");
if (fp == NULL) /* fork or pipe failed; or out-of-mem */
{
return result;
}
size_t sz;
char buf[BUFSIZ + 1];
while ((sz = fread(buf, 1, sizeof(buf)-1, fp)) > 0)
{
buf[sz] = '\0';
result += buf;
}
pclose(fp);
return result;
}
|