-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
#ifndef APPROVALTESTS_CPP_SYSTEMLAUNCHER_H | ||
#define APPROVALTESTS_CPP_SYSTEMLAUNCHER_H | ||
|
||
#include <iostream> | ||
#include <stdlib.h> | ||
#include <string> | ||
#include "../SystemUtils.h" | ||
#include "../FileUtils.h" | ||
#include <vector> | ||
#include <numeric> | ||
#include "CommandLauncher.h" | ||
|
||
class SystemLauncher : public CommandLauncher | ||
{ | ||
public: | ||
bool exists(const std::string& command) | ||
{ | ||
bool foundByWhich = false; | ||
if (!SystemUtils::isWindowsOs()) { | ||
std::string which = "which " + command + " > /dev/null 2>&1"; | ||
int result = system(which.c_str()); | ||
foundByWhich = (result == 0); | ||
} | ||
return foundByWhich || FileUtils::fileExists(command); | ||
|
||
} | ||
|
||
bool Launch(std::vector<std::string> argv) | ||
{ | ||
if (!exists(argv.front())) | ||
{ | ||
return false; | ||
} | ||
|
||
std::string command = std::accumulate(argv.begin(), argv.end(), std::string(""), [](std::string a, std::string b) {return a + " " + "\"" + b + "\""; }); | ||
std::string launch = SystemUtils::isWindowsOs() ? ("start \"\" " + command) : (command + " &"); | ||
system(launch.c_str()); | ||
return true; | ||
} | ||
}; | ||
|
||
#endif //APPROVALTESTS_CPP_SYSTEMLAUNCHER_H |