From 1d3e221a7a20bfd03517e3ae1e35e4a309a69b6a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 10 Dec 2017 01:10:48 +0100 Subject: Add support for dependencies in global lib dir Global lib dir is located at ~/.sibs/lib TODO: If global lib dir doesn't exist, download it from github/server --- src/Exec.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Exec.cpp (limited to 'src/Exec.cpp') diff --git a/src/Exec.cpp b/src/Exec.cpp new file mode 100644 index 0000000..b245fd4 --- /dev/null +++ b/src/Exec.cpp @@ -0,0 +1,28 @@ +#include "../include/Exec.hpp" + +namespace sibs +{ + Result exec(const char *cmd, bool print) + { + char buffer[128]; + std::string result; + FILE *pipe = popen(cmd, "r"); + if(!pipe) + return Result::Err("popen() failed"); + + while(!feof(pipe)) + { + if(fgets(buffer, 128, pipe)) + { + result += buffer; + if(print) + printf("%s", buffer); + } + } + + ExecResult execResult; + execResult.execStdout = result; + execResult.exitCode = WEXITSTATUS(pclose(pipe)); + return Result::Ok(execResult); + } +} \ No newline at end of file -- cgit v1.2.3