After make lib, and testing
This commit is contained in:
commit
25a65c6cfd
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"string": "cpp"
|
||||||
|
}
|
||||||
|
}
|
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Library for executing bash commands with captured output.
|
||||||
|
|
||||||
|
|
||||||
|
The output of the bash command is saved in a C++ string.
|
15
lib/exec.hpp
Normal file
15
lib/exec.hpp
Normal file
@ -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
|
21
src/exec.cpp
Normal file
21
src/exec.cpp
Normal file
@ -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;
|
||||||
|
}
|
3
test/bash_cmd.sh
Normal file
3
test/bash_cmd.sh
Normal file
@ -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";
|
1
test/compile.sh
Normal file
1
test/compile.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
g++ test.cpp ../src/* -o test.o
|
15
test/test.cpp
Normal file
15
test/test.cpp
Normal file
@ -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;
|
||||||
|
}
|
BIN
test/test.o
Executable file
BIN
test/test.o
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user