UnixExec

Starting from version 2.0.2, this command is used to execute a z/OS UNIX command.

Example 1: Execute a Git command with options and save output to a log file.

UnixExec exec = new UnixExec();
List<String> options = Arrays.asList("rev-parse", "--abbrev-ref", "HEAD");
exec.command("git").options(options);
exec.output("stdout.log");

int rc = exec.execute();

Example 2: UNIX Exec will default to the directory where the JVM was started from as reported by system property user.dir. The working directory can be changed by passing the absolute path of a directory.

UnixExec exec = new UnixExec().command("pwd");
exec.workingDirectory("/u/USER1/Project");
exec.execute();

Example 3: UnixExec can merge the output and error streams to a single file, or split them into two output files. Merging errors defaults to false.

// Standard output
exec.output("stdout.log");

// Error output
exec.error("stderror.log");

// Standard and error merged
exec.output("out.log").mergeErrors(true);

Example 4: The default timeout to wait for a process is one hour, but can be adjusted by using setTimeout().

// Import TimeUnit
import java.util.concurrent.TimeUnit;

// Set timeout to 10 minutes
exec.setTimeout(10, TimeUnit.MINUTES);

// Set timeout to 8 hours
exec.setTimeout(8, TimeUnit.HOURS);

// Set timeout to 1 day
exec.setTimeout(1, TimeUnit.DAYS);