-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
40 lines (34 loc) · 813 Bytes
/
Utils.cpp
File metadata and controls
40 lines (34 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "Utils.h"
namespace Utils
{
const int getBufferSize()
{
return 255;
}
std::string myExec(const char* command)
{
FILE* pipe = popen(command, "r");
if (pipe == 0) {
Logger::getInstance()->error("Can't perform popen() operation.");
exit(CANT_OPEN_PIPE);
}
char buffer[getBufferSize()];
std::string result = "";
while(!feof(pipe)) {
if(fgets(buffer, getBufferSize(), pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}
std::vector<std::string>& split(const std::string& input,
const char delimiter,
std::vector<std::string>& elements) {
std::stringstream ss(input);
std::string item;
while(getline(ss, item, delimiter)) {
elements.push_back(item);
}
return elements;
}
}