2025-05-10 13:54:38 +12:00
..
.
2025-05-10 13:47:17 +12:00
2025-05-10 12:43:25 +12:00
.
2025-05-10 13:47:17 +12:00
.
2025-05-10 13:47:17 +12:00
.
2025-05-10 13:47:17 +12:00
.
2025-05-10 13:47:17 +12:00
2025-05-10 13:54:38 +12:00
.
2025-05-10 13:47:17 +12:00

Runner

Simple c++ demonstration program of the dropshell runner library.

use: runner BASE64COMMAND

BASE64COMMAND is Base64 encoded json. The json format is as described below. The exit code is that of the command run, or -1 if the command couldn't be run.

The c++ library used, which is contained in this codebase, has one simple function:

typedef struct sSSHInfo {
    std::string host;
    std::string user;
    std::string port;
} sSSHInfo;


static int execute_cmd(
    const std::string& command,
    const std::vector<std::string>& args,
    const std::string& working_dir,
    const std::map<std::string, std::string>& env,
    bool silent,
    bool interactive,
    sSSHInfo * sshinfo = nullptr,
    std::string* output = nullptr,
);

If SSH information is provided, the command will be executed on the remote server. Otherwise on the local machine.

If output is provided, the output of the command is captured.

If interactive is true, then an interactive session is created - e.g. for running nano to remotely edit a file, or sshing into a docker container from the remote host.

If silent is true, then all output is suppressed.

Before the command is run, the current directory is changed to working_dir on the remote host (or local host if no ssh info provided).

BASE64COMMAND JSON Format

The BASE64COMMAND argument should be a Base64-encoded JSON object with the following fields:

  • command (string, required): The command to execute (e.g., "ls").
  • args (array of strings, optional): Arguments to pass to the command (e.g., ["-l", "/tmp"]).
  • working_dir (string, optional): Directory to change to before running the command.
  • env (object, optional): Environment variables to set (e.g., {"FOO": "bar"}).
  • silent (boolean, optional): If true, suppress all output. Default: false.
  • interactive (boolean, optional): If true, run the command interactively. Default: false.
  • sshinfo (object, optional): If present, run the command on a remote host (not implemented in demo):
    • host (string): Hostname or IP.
    • user (string): Username.
    • port (string): SSH port.

Example JSON

{
  "command": "ls",
  "args": ["-l", "/tmp"],
  "working_dir": "/",
  "env": {"FOO": "bar"},
  "silent": false,
  "interactive": false
}

To use, encode the JSON as a single line, then base64 encode it:

echo -n '{"command":"ls","args":["-l","/tmp"],"working_dir":"/","env":{"FOO":"bar"},"silent":false,"interactive":false}' | base64

Then run:

./build/runner <BASE64COMMAND>