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

Function executeCommand

src/helper/linux/utils.cpp:19–71  ·  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 cmdLine += " '";
26 for (char c : *it) {
27 if (c == '\'') {
28 cmdLine += "'\\''";
29 } else {
30 cmdLine += c;
31 }
32 }
33 cmdLine += "'";
34 }
35
36 if (pOutputStr) {
37 pOutputStr->clear();
38 }
39
40 redi::ipstream proc(cmdLine, redi::pstreams::pstdout | redi::pstreams::pstderr);
41 std::string line;
42 // read child's stdout
43 while (std::getline(proc.out(), line)) {
44 if (pOutputStr) {
45 *pOutputStr += line + "\n";
46 }
47 }
48 // if reading stdout stopped at EOF then reset the state:
49 if (proc.eof() && proc.fail()) {
50 proc.clear();
51 }
52
53 if (appendFromStdErr) {
54 // read child's stderr
55 while (std::getline(proc.err(), line)) {
56 if (pOutputStr) {
57 *pOutputStr += line + "\n";
58 }
59 }
60 }
61
62 proc.close();
63 if (proc.rdbuf()->exited()) {
64 // status() is the raw wait-status from waitpid (e.g. exit code 2 -> 512), which
65 // is misleading when logged. Normalize to the real exit code so callers and logs
66 // see what the command actually returned. exited() == WIFEXITED, so WEXITSTATUS
67 // is well-defined here.
68 return WEXITSTATUS(proc.rdbuf()->status());
69 }
70 return 0;
71}
72
73
74size_t findCaseInsensitive(std::string data, std::string toSearch, size_t pos)

Callers 15

changeMtuFunction · 0.70
executeTaskKillFunction · 0.70
startCtrldFunction · 0.70
setMacAddressFunction · 0.70
setDnsLeakProtectEnabledFunction · 0.70
restoreRulesMethod · 0.70
hasBlockJumpMethod · 0.70
dnsLeaksJumpPosMethod · 0.70
inputJumpExistsMethod · 0.70
disableMethod · 0.70
getHotspotAdapterMethod · 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