After make lib, and testing

dev v0.1_beta
marcelb 1 year ago
commit 25a65c6cfd
  1. 5
      .vscode/settings.json
  2. 4
      README.md
  3. 15
      lib/exec.hpp
  4. 21
      src/exec.cpp
  5. 3
      test/bash_cmd.sh
  6. 1
      test/compile.sh
  7. 15
      test/test.cpp
  8. BIN
      test/test.o

@ -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…
Cancel
Save