Process Runner

GitHub license Build Status codecov Maven Central Quality Gate Technical debt ratio SonarCloud Code Coverage codebeat badge

codecov.io

Process Runner is java based library using which one can execute system process or scripts [shell scripts, batch file, python scripts, ruby scripts etc] from inside your java program.

Show me the code

// Create configuration
Configuration configuration = new ConfigBuilder("bash", "./script.sh")
    .setMasterLogFile(new File("~/masterlog.json"), Boolean.TRUE, Charset.defaultCharset())
    .enableLogStreaming(Boolean.TRUE).setParam("param1")
    .setParamList(Arrays.asList("param2", "param3"))
    .build();
{
  // Method 1 - start the runner at later point of time in sync and async manner.
  Runner runner = RunnerFactory.getRunner(configuration);
  Output output = runner.run();
  output = runner.runAsync().get();
}
{
  // Method 2 - Start instantly synchronously and async only.
  Output output = RunnerFactory.startProcess(configuration);
  output = RunnerFactory.startAsyncProcess(configuration).get();
}

Processrunner details

ProcessRunner library can run any system process from java and have the following features :-

  1. Only the interpreter and and the command to run in ConfigurationBuilder are mandatory. For optional fields please read forward.
  2. Master log file: Master log file can be set with file marked for auto delete and charset.
  3. Log Streaming: The project uses Slf4j api. It will try to stream the logs in realtime via Slf4j.
  4. Set a param: Set a parameter for the command. This method can be used multiple times.
  5. Set param from a list of String: Set a parameter for the command from a List of String
  6. The process itself can run in seperate or the same thread.
  7. The logs are handled in a seperate threads and is written to disk immediately. [ iff masterlog file is configured ]
  8. From Output object the log can be saved as : SYSOUT only, SYSERR only or Both SYSOUT and SYSERR. [ iff masterlog file is configured ]
  9. From Output pattern of text can be searched which might return a true/false or a list of matching record. [ iff masterlog file is configured ]