The JBang team has introduced JBang Jash (pronounced Jazz), a Java library designed to simplify the execution of external processes and shell commands through a fluent and predictable API, aiming to addresses the common complexities and boilerplate developers face when using standard Java APIs like ProcessBuilder
and the overloaded exec()
method, defined in Runtime
, for these tasks.
JBang Jash aims to facilitate intuitive and chainable process execution, automatically handling the underlying management of input/output streams. Non-zero exit codes are handled as exceptions by default, a behavior which can be customized. It also supports piping commands in a pipeline, eliminating the needs of manual stream forwarding, and also detects the appropriate shell environment, such as Bash, CMD, or Powershell, based on the operation system.
Let’s see a shell example using pure Java that requires manual stream handling, and explicit error checking, the example just run the “git status” and capture the output:
//without Jash
ProcessBuilder builder = new ProcessBuilder("git", "status");
builder.redirectErrorStream(true);
Process process = builder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
int exitCode = process.waitFor();
if (exitCode != 0) {
throw new RuntimeException("Process exited with error code " + exitCode);
}
and with Jash:
Jash.start("git", "status").stream().forEach(System.out::println);
Let’s also see an example of how to piping commands in Java, where a lowercase text is transformed to uppercase by piping the output of echo
into the tr
command:
//without Jash
ProcessBuilder echoBuilder = new ProcessBuilder("echo", "hello world");
Process echoProcess = echoBuilder.start();
ProcessBuilder trBuilder = new ProcessBuilder("tr", "a-z", "A-Z");
Process trProcess = trBuilder.start();
try (
BufferedReader reader = new BufferedReader(new InputStreamReader(echoProcess.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(trProcess.getOutputStream()))
) {
String line;
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.newLine();
}
writer.flush();
trProcess.getOutputStream().close(); // signal EOF to tr
}
int echoExit = echoProcess.waitFor();
int trExit = trProcess.waitFor();
if (echoExit != 0) {
throw new RuntimeException("echo failed with code " + echoExit);
}
try (BufferedReader resultReader = new BufferedReader(new InputStreamReader(trProcess.getInputStream()))) {
String line;
while ((line = resultReader.readLine()) != null) {
System.out.println(line); // Expected: HELLO WORLD
}
}
if (trExit != 0) {
throw new RuntimeException("tr failed with code " + trExit);
}
and with Jash:
String result = Jash.start("echo", "hello world")
.pipe("tr", "a-z", "A-Z")
.get();
System.out.println(result.trim()); // Outputs: HELLO WORLD
JBang Jash is based on a project named “fluent-process” by OnGres, Inc. in 2020. After years without an official release, the project was forked and renamed to “jash” (a reference to Java and Shell) in 2025 to reflect its focus on providing a more idiomatic Java 17+ interface for working with shell processes and streams.
It is important to note that Jash can be integrated to any Java Project, without needing to use the JBang CLI tool.
More examples and details about JBang Jash can be found in the GitHub repository.