Skip to content

sagiegurari/c_scriptexec

Repository files navigation

scriptexec

CI Release license

Invoke complex multi command scripts with a single C api call.

Overview

This library enables to invoke complex multi command scripts with a single C api call and get the script status code and out/err.

Usage

#include "scriptexec.h"
#include <stdio.h>
#include <stdlib.h>


int main()
{
  // invoke the script with default options
  struct ScriptExecResult result = scriptexec_run("echo 1\necho 2\necho 3\necho 4");

  printf("Code: %d\nOutput:\n%s\nError:\n%s\n", result.code, result.out, result.err);

  // invoke the script with custom options
  struct ScriptExecOptions options = scriptexec_create_options();
  options.runner            = "bash";     // default is 'sh'
  options.working_directory = "./target"; // default to current working directory
  options.exit_on_error     = true;       // default true, will break script execution on any error
  options.print_commands    = true;       // default false, if true will print every command before invocation

  result = scriptexec_run_with_options("echo 1\necho 2\necho 3\necho 4", options);
  printf("Code: %d\nOutput:\n%s\nError:\n%s\n", result.code, result.out, result.err);

  free(result.out);
  free(result.err);
}

Contributing

See contributing guide

Release History

See Changelog

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.