forked from mierl/ZHT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.cpp
More file actions
36 lines (28 loc) · 642 Bytes
/
exec.cpp
File metadata and controls
36 lines (28 loc) · 642 Bytes
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
31
32
33
/*
* exec.cpp
*
* Created on: Jan 16, 2012
* Author: tony
*/
#include <string>
#include <iostream>
#include <stdio.h>
using namespace std;
string exec(string str) {
char* cmd = (char*)str.c_str();
FILE* pipe = popen(cmd, "r");
if (!pipe) return "ERROR";
char buffer[128];
string result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}
int main(){
const string cmd = "cat /proc/personality.sh | grep BG_PSETORG";
string result = exec(cmd);
cout << "Result: "<< result<<endl;
}