commit
25a65c6cfd
@ -0,0 +1,5 @@ |
||||
{ |
||||
"files.associations": { |
||||
"string": "cpp" |
||||
} |
||||
} |
@ -0,0 +1,4 @@ |
||||
# Library for executing bash commands with captured output. |
||||
|
||||
|
||||
The output of the bash command is saved in a C++ string. |
@ -0,0 +1,15 @@ |
||||
#ifndef _TRM_ |
||||
#define _TRM_ |
||||
|
||||
#include <iostream> |
||||
// #include <fstream>
|
||||
// #include <map>
|
||||
// #include <vector>
|
||||
#include <string> |
||||
|
||||
using namespace std; |
||||
|
||||
string exec(const string command); |
||||
|
||||
|
||||
#endif |
@ -0,0 +1,21 @@ |
||||
#include "../lib/exec.hpp" |
||||
|
||||
/**
|
||||
* Funkcija za pozivanje bash naredbi s odgovorom |
||||
*/ |
||||
|
||||
string exec(const string command) { |
||||
FILE *fds; |
||||
char cstr[200]; |
||||
fds = popen(command.c_str(), "r"); |
||||
if (fds == NULL) { |
||||
throw string("[ERROR] Cant pipe stream in execute command "); |
||||
} |
||||
|
||||
string cppstr; |
||||
while (fgets(cstr, sizeof(cstr), fds) != NULL) { |
||||
cppstr += cstr; |
||||
} |
||||
pclose(fds); |
||||
return cppstr; |
||||
} |
@ -0,0 +1,3 @@ |
||||
echo "WARNING: key file (/etc/bind/rndc.key) exists, but using default configuration file (/etc/bind/rndc.conf)"; |
||||
sleep 4s; |
||||
echo "zone reload up-to-date"; |
@ -0,0 +1 @@ |
||||
g++ test.cpp ../src/* -o test.o |
@ -0,0 +1,15 @@ |
||||
#include <iostream> |
||||
|
||||
#include "../lib/exec.hpp" |
||||
|
||||
using namespace std; |
||||
|
||||
int main() { |
||||
|
||||
string out = exec("bash bash_cmd.sh"); |
||||
|
||||
cout << out << endl; |
||||
|
||||
|
||||
return 0; |
||||
} |
Binary file not shown.
Loading…
Reference in new issue