MCPcopy Create free account
hub / github.com/Windscribe/Desktop-App / executeCommand

Function executeCommand

src/helper/macos/utils.cpp:19–77  ·  view source on GitHub ↗

based on 3rd party lib (http://pstreams.sourceforge.net/)

Source from the content-addressed store, hash-verified

17
18// based on 3rd party lib (http://pstreams.sourceforge.net/)
19int executeCommand(const std::string &cmd, const std::vector<std::string> &args,
20 std::string *pOutputStr, bool appendFromStdErr)
21{
22 std::string cmdLine = cmd;
23
24 for (auto it = args.begin(); it != args.end(); ++it)
25 {
26 cmdLine += " '";
27 for (char c : *it) {
28 if (c == '\'') {
29 cmdLine += "'\\''";
30 } else {
31 cmdLine += c;
32 }
33 }
34 cmdLine += "'";
35 }
36
37 if (pOutputStr)
38 {
39 pOutputStr->clear();
40 }
41
42 redi::ipstream proc(cmdLine, redi::pstreams::pstdout | redi::pstreams::pstderr);
43 std::string line;
44 // read child's stdout
45 while (std::getline(proc.out(), line))
46 {
47 if (pOutputStr)
48 {
49 *pOutputStr += line + "\n";
50 }
51 }
52 // if reading stdout stopped at EOF then reset the state:
53 if (proc.eof() && proc.fail())
54 {
55 proc.clear();
56 }
57
58 if (appendFromStdErr) {
59 // read child's stderr
60 while (std::getline(proc.err(), line))
61 {
62 if (pOutputStr)
63 {
64 *pOutputStr += line + "\n";
65 }
66 }
67 }
68
69 proc.close();
70 if (proc.rdbuf()->exited())
71 {
72 return proc.rdbuf()->status();
73 }
74 // The child did not exit normally (signal, stop, etc.). Callers compare the return
75 // value to 0 to decide success, so a 0 here would falsely report success.
76 return -1;

Callers 15

changeMtuFunction · 0.70
executeTaskKillFunction · 0.70
startCtrldFunction · 0.70
setMacAddressFunction · 0.70
setDnsScriptEnabledFunction · 0.70
deleteRouteFunction · 0.70
FirewallControllerMethod · 0.70
fullApplyMethod · 0.70
loadTableDefMethod · 0.70
loadAnchorMethod · 0.70
getRulesMethod · 0.70
disableMethod · 0.70

Calls 5

clearMethod · 0.45
closeMethod · 0.45
exitedMethod · 0.45
rdbufMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected