Seems to be working!!
This commit is contained in:
@ -68,8 +68,9 @@ bool execute_local_command(const sCommand& command, bool silent, bool safe) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool execute_local_command_and_capture_output(const sCommand& command, std::string &output, bool silent, bool safe)
|
||||
bool execute_local_command_and_capture_output(const sCommand& command, std::string * output, bool silent, bool safe)
|
||||
{
|
||||
ASSERT_MSG(output != nullptr, "Output string must be provided");
|
||||
if (command.get_command_to_run().empty())
|
||||
return false;
|
||||
cStyle style = safe ? cStyle::Safe : cStyle::Raw;
|
||||
@ -80,7 +81,7 @@ bool execute_local_command_and_capture_output(const sCommand& command, std::stri
|
||||
}
|
||||
char buffer[128];
|
||||
while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
|
||||
output += buffer;
|
||||
(*output) += buffer;
|
||||
}
|
||||
int ret = pclose(pipe);
|
||||
return EXITSTATUSCHECK(ret);
|
||||
@ -90,19 +91,19 @@ bool execute_local_command_and_capture_output(const sCommand& command, std::stri
|
||||
|
||||
bool execute_local_command(const sCommand & command, cMode mode, std::string * output /* = nullptr */)
|
||||
{
|
||||
if (mode & cMode::Interactive) {
|
||||
ASSERT_MSG((mode & cMode::CaptureOutput), "Interactive mode and capture output mode cannot be used together");
|
||||
if (hasFlag(mode, cMode::Interactive)) {
|
||||
ASSERT_MSG(! hasFlag(mode, cMode::CaptureOutput), "Interactive mode and capture output mode cannot be used together");
|
||||
ASSERT_MSG(output == nullptr, "Interactive mode and an output string cannot be used together");
|
||||
ASSERT_MSG(! (mode & cMode::SafeCommand), "Interactive mode and safe command mode cannot be used together");
|
||||
return execute_local_command_interactive(command, mode & cMode::Silent);
|
||||
ASSERT_MSG(! hasFlag(mode, cMode::SafeCommand), "Interactive mode and safe command mode cannot be used together");
|
||||
return execute_local_command_interactive(command, hasFlag(mode, cMode::Silent));
|
||||
}
|
||||
|
||||
if (mode & cMode::CaptureOutput) {
|
||||
if (hasFlag(mode, cMode::CaptureOutput)) {
|
||||
ASSERT_MSG(output != nullptr, "Capture output mode requires an output string to be provided");
|
||||
return execute_local_command_and_capture_output(command, *output, mode & cMode::Silent, mode & cMode::SafeCommand);
|
||||
return execute_local_command_and_capture_output(command, output, hasFlag(mode, cMode::Silent), hasFlag(mode, cMode::SafeCommand));
|
||||
}
|
||||
|
||||
return execute_local_command(command, mode & cMode::Silent, mode & cMode::SafeCommand);
|
||||
return execute_local_command(command, hasFlag(mode, cMode::Silent), hasFlag(mode, cMode::SafeCommand));
|
||||
}
|
||||
|
||||
bool execute_ssh_command(const sSSHInfo &ssh_info, const sCommand &command, cMode mode, std::string *output)
|
||||
@ -110,13 +111,14 @@ bool execute_ssh_command(const sSSHInfo &ssh_info, const sCommand &command, cMod
|
||||
if (command.get_command_to_run().empty())
|
||||
return false;
|
||||
|
||||
ASSERT_MSG(!(mode & cMode::Interactive && mode & cMode::SafeCommand), "Safe command mode must not be used with Interactive mode");
|
||||
ASSERT_MSG(!(hasFlag(mode, cMode::Interactive) && hasFlag(mode, cMode::SafeCommand)), "Safe command mode must not be used with Interactive mode");
|
||||
ASSERT_MSG(!(hasFlag(mode, cMode::CaptureOutput) && output == nullptr), "Capture output mode must be used with an output string");
|
||||
|
||||
std::stringstream ssh_cmd;
|
||||
ssh_cmd << "ssh -p " << ssh_info.port << " " << (mode & cMode::Interactive ? "-tt " : "")
|
||||
ssh_cmd << "ssh -p " << ssh_info.port << " " << (hasFlag(mode, cMode::Interactive) ? "-tt " : "")
|
||||
<< ssh_info.user << "@" << ssh_info.host;
|
||||
|
||||
sCommand ssh_command(ssh_cmd.str() + " bash -c " + quote(escapequotes(command.construct_cmd(mode & cMode::SafeCommand ? cStyle::Safe : cStyle::Raw))));
|
||||
sCommand ssh_command(ssh_cmd.str() + " bash -c " + quote(escapequotes(command.construct_cmd(hasFlag(mode, cMode::SafeCommand) ? cStyle::Safe : cStyle::Raw))));
|
||||
|
||||
bool rval = execute_local_command(ssh_command, mode, output);
|
||||
|
||||
|
Reference in New Issue
Block a user