diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-10 01:10:48 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2017-12-10 01:12:08 +0100 |
commit | 1d3e221a7a20bfd03517e3ae1e35e4a309a69b6a (patch) | |
tree | fdb38039d12cf38e9ac6102118727b78437cf3db /src/Exec.cpp | |
parent | 2ed7d0b09caa872e44e2eb09b09b2387e93f9b34 (diff) |
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
Diffstat (limited to 'src/Exec.cpp')
-rw-r--r-- | src/Exec.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
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<ExecResult> exec(const char *cmd, bool print) + { + char buffer[128]; + std::string result; + FILE *pipe = popen(cmd, "r"); + if(!pipe) + return Result<ExecResult>::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<ExecResult>::Ok(execResult); + } +}
\ No newline at end of file |