-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruncommandscorechecker.cpp
More file actions
64 lines (62 loc) · 1.98 KB
/
runcommandscorechecker.cpp
File metadata and controls
64 lines (62 loc) · 1.98 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "runcommandscorechecker.h"
#ifdef __linux__
#include "boost/process.hpp"
#endif
RunCommandScoreChecker::RunCommandScoreChecker()
{
this->description="Command Output Checker";
this->points=1;
this->checkerType="RunCommand";
this->bSearchstringexist=true;
}
void RunCommandScoreChecker::setCommand(std::string command)
{
this->command=command;
}
std::string RunCommandScoreChecker::getCommand()
{
return this->command;
}
std::string RunCommandScoreChecker::getCommandOutput()
{
return this->commandoutput;
}
void RunCommandScoreChecker::executeCommand()
{
#ifdef _WIN32
this->commandoutput=exec(this->command.c_str());
#elif __linux__
boost::process::ipstream output, whicherr, whichout;
std::string output1;
//Check from https://stackoverflow.com/questions/890894/portable-way-to-find-out-if-a-command-exists-c-c
if (!this->command.empty() && !boost::process::system("which " + this->command.substr(0, this->command.find(" ")),boost::process::std_err > whicherr, boost::process::std_out > whichout)){
boost::process::system(this->command, boost::process::std_out > output);
this->commandoutput= std::string((std::istreambuf_iterator<char>(output)), std::istreambuf_iterator<char>());
}else{
std::cerr << "Warning: no command \"" << this->command << "\".";
this->commandoutput="";
}
#endif
}
void RunCommandScoreChecker::checkState()
{
executeCommand();
boost::regex expression(this->searchstring);
this->state=(boost::regex_search(this->commandoutput,expression,boost::match_any)==this->bSearchstringexist); //logical xnor
}
void RunCommandScoreChecker::setSearchExist(bool exist)
{
this->bSearchstringexist=exist;
}
bool RunCommandScoreChecker::getSearchExist()
{
return bSearchstringexist;
}
void RunCommandScoreChecker::setSearchString(std::string searchstring)
{
this->searchstring=searchstring;
}
std::string RunCommandScoreChecker::getSearchString()
{
return this->searchstring;
}