dropshell release 2025.0518.1300
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
#include "utils/b64ed.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils/directories.hpp"
|
||||
#include "utils/output.hpp"
|
||||
|
||||
namespace dropshell
|
||||
{
|
||||
@ -21,6 +22,10 @@ namespace dropshell
|
||||
return (ret != -1 && WIFEXITED(ret) && (WEXITSTATUS(ret) == 0)); // ret is -1 if the command failed to execute.
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// execute_local_command_interactive
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
bool execute_local_command_interactive(const sCommand &command)
|
||||
{
|
||||
if (command.get_command_to_run().empty())
|
||||
@ -51,6 +56,9 @@ namespace dropshell
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// execute_local_command_and_capture_output
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
bool execute_local_command_and_capture_output(const sCommand &command, std::string *output)
|
||||
{
|
||||
ASSERT(output != nullptr, "Output string must be provided");
|
||||
@ -71,6 +79,9 @@ namespace dropshell
|
||||
return EXITSTATUSCHECK(ret);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// execute_local_command
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
bool execute_local_command(std::string command, std::string *output, cMode mode)
|
||||
{
|
||||
return execute_local_command("", command, {}, output, mode);
|
||||
@ -100,17 +111,25 @@ namespace dropshell
|
||||
return false;
|
||||
bool silent = hasFlag(mode, cMode::Silent);
|
||||
std::string full_cmd = command.construct_cmd(localpath::agent()) + " 2>&1" + (silent ? " > /dev/null" : "");
|
||||
int ret = system(full_cmd.c_str());
|
||||
|
||||
int ret=0;
|
||||
{
|
||||
SwitchColour sc(sColour::DEBUG, std::cerr);
|
||||
ret = system(full_cmd.c_str());
|
||||
}
|
||||
|
||||
bool ok = EXITSTATUSCHECK(ret);
|
||||
if (!ok && !silent)
|
||||
{
|
||||
std::cerr << "Error: Failed to execute command: " << std::endl;
|
||||
std::cerr << full_cmd << std::endl;
|
||||
PrintError("Error: Failed to execute command: ");
|
||||
PrintError(full_cmd);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// execute_ssh_command
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
bool execute_ssh_command(const sSSHInfo &ssh_info, const sCommand &remote_command, cMode mode, std::string *output)
|
||||
{
|
||||
if (remote_command.get_command_to_run().empty())
|
||||
@ -144,6 +163,9 @@ namespace dropshell
|
||||
return rval;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// makesafecmd
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
std::string sCommand::makesafecmd(std::string agent_path, const std::string &command) const
|
||||
{
|
||||
if (command.empty())
|
||||
@ -153,6 +175,9 @@ namespace dropshell
|
||||
return commandstr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
// construct_cmd
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
std::string sCommand::construct_cmd(std::string agent_path) const
|
||||
{
|
||||
if (mCmd.empty())
|
||||
|
Reference in New Issue
Block a user