This problem may be related to sub-process's input stream buffers.

You should clear the sub-process's input stream buffers.

These stream buffers got increased within the parent process's memory with time and at some moment your sub-process will stop responding.

There are few options to make sub-process work normally

  1. Read continuously from sub-process's input streams
  2. Redirect sub-process's input streams
  3. Close sub-process's input streams

Closing sub-process's input streams

ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = processBuilder.start();
InputStream inStream = process.getInputStream();
InputStream errStream = process.getErrorStream();
try {
    inStream.close();
    errStream.close();
} catch (IOException e1) {
}
process.waitFor();

Reading sub-process's input streams

    ProcessBuilder processBuilder = new ProcessBuilder(command);
    Process process = processBuilder.start();
    InputStreamReader tempReader = new InputStreamReader(new BufferedInputStream(p.getInputStream()));
    final BufferedReader reader = new BufferedReader(tempReader);
    InputStreamReader tempErrReader = new InputStreamReader(new BufferedInputStream(p.getErrorStream()));
    final BufferedReader errReader = new BufferedReader(tempErrReader);

    try {
        while ((line = reader.readLine()) != null) {
        }
    } catch (IOException e) {
    }

    try {
        while ((line = errReader.readLine()) != null) {
        }
    } catch (IOException e) {
    }
    process.waitFor();

Redirecting sub-process's input streams

ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.redirectInput();
processBuilder.redirectError();
Process process = processBuilder.start();
process.waitFor();
Answer from Anil Agrawal on Stack Overflow
🌐
Coderanch
coderanch.com › t › 725153 › java › Java-process-builder-returning-correct
Java process builder not returning correct (or any) output (Java in General forum at Coderanch)
January 11, 2020 - Bod McLeon wrote:And the output - well - that's non-existent (there is none - nothing is written to the console). Most likely an exception is being thrown, and you are simply ignoring it. You should at least print the stack. I would also printout the exit value: Edit: updated code ... I merged your stuff with the following thread. I hope that is okay by you. ... I am trying to call a python script from Java. I am using ProcessBuilder to call the python script and it does work (sort of) It's very easy to call the python script on windows, by using the command 'python' which should point to the latest version of python.
🌐
Baeldung
baeldung.com › home › java › core java › guide to java.lang.processbuilder api
Guide to java.lang.ProcessBuilder API | Baeldung
November 26, 2025 - In the next section, we’re going to take a look at what additions were made to the ProcessBuilder API in Java 9. When working with the ProcessBuilder API, we may need to pass arguments that contain spaces, such as strings with multiple words or file paths under directories. If not handled correctly, these arguments can cause the command to fail or be misinterpreted by the operating system.
Top answer
1 of 2
2

This problem may be related to sub-process's input stream buffers.

You should clear the sub-process's input stream buffers.

These stream buffers got increased within the parent process's memory with time and at some moment your sub-process will stop responding.

There are few options to make sub-process work normally

  1. Read continuously from sub-process's input streams
  2. Redirect sub-process's input streams
  3. Close sub-process's input streams

Closing sub-process's input streams

ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = processBuilder.start();
InputStream inStream = process.getInputStream();
InputStream errStream = process.getErrorStream();
try {
    inStream.close();
    errStream.close();
} catch (IOException e1) {
}
process.waitFor();

Reading sub-process's input streams

    ProcessBuilder processBuilder = new ProcessBuilder(command);
    Process process = processBuilder.start();
    InputStreamReader tempReader = new InputStreamReader(new BufferedInputStream(p.getInputStream()));
    final BufferedReader reader = new BufferedReader(tempReader);
    InputStreamReader tempErrReader = new InputStreamReader(new BufferedInputStream(p.getErrorStream()));
    final BufferedReader errReader = new BufferedReader(tempErrReader);

    try {
        while ((line = reader.readLine()) != null) {
        }
    } catch (IOException e) {
    }

    try {
        while ((line = errReader.readLine()) != null) {
        }
    } catch (IOException e) {
    }
    process.waitFor();

Redirecting sub-process's input streams

ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.redirectInput();
processBuilder.redirectError();
Process process = processBuilder.start();
process.waitFor();
2 of 2
0

(from comments)

Looks like process hang is due to out/error streams becoming full. You need to consume these streams; possibly via a thread.

Java7 provides another way to redirect output.

Related : http://alvinalexander.com/java/java-exec-processbuilder-process-3

🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › ProcessBuilder.html
ProcessBuilder (Java Platform SE 8 )
April 21, 2026 - Modifying a process builder's attributes will affect processes subsequently started by that object's start() method, but will never affect previously started processes or the Java process itself. Most error checking is performed by the start() method. It is possible to modify the state of an object so that start() will fail. For example, setting the command attribute to an empty list will not throw an exception unless start() is invoked. Note that this class is not synchronized. If multiple threads access a ProcessBuilder instance concurrently, and at least one of the threads modifies one of the attributes structurally, it must be synchronized externally.
Top answer
1 of 1
1

The error message says that Java does not find an executable called zip in the current directory or on the path, which can be seen with:

String systemPath = System.getenv("PATH");
System.out.println("PATH="+systemPath);

Fix your launcher to include the full path to "zip" or fix the PATH used for your Java VM to include a directory that contains zip.

myListOfString.add("/the/path/to/zip");

or something like this (depending on your shell / terminal)

export PATH=/the/path/to:$PATH

As @Abra suggests, there are better ways to ZIP inside Java without relying on ProcessBuilder such as:

public static void zip(Path dir, Path zip) throws IOException
{
    Map<String, String> env = Map.of("create", "true");
    try (FileSystem fs = FileSystems.newFileSystem(zip, env))
    {
        // This predicate processed the action because it makes use of BasicFileAttributes
        // Rather than process a forEach stream which has to call Files.isDirectory(path)
        BiPredicate<Path, BasicFileAttributes> foreach = (p,a) -> {
            copy(p,a, fs.getPath("/"+dir.relativize(p)));
            return false;
        };

        Files.find(dir, Integer.MAX_VALUE, foreach).count();
    }
    System.out.println("ZIPPED "+dir +" to "+zip);
}
private static void copy(Path from, BasicFileAttributes a, Path target)
{
    System.out.println("Copy "+(a.isDirectory() ? "DIR " : "FILE")+" => "+target);
    try
    {
        if (a.isDirectory())
            Files.createDirectories(target);
        else if (a.isRegularFile())
            Files.copy(from, target, StandardCopyOption.REPLACE_EXISTING);
    }
    catch (IOException e)
    {
        throw new UncheckedIOException(e);
    }
}
🌐
LinuxQuestions.org
linuxquestions.org › questions › programming-9 › problem-with-processbuilder-in-java-938459
[SOLVED] Problem with ProcessBuilder in java
April 6, 2012 - Hi All, I am trying to invoke a command line script from java using ProcessBuilder. Here is how my code looks like. ProcessBuilder pb = new
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › ProcessBuilder.html
ProcessBuilder (Java Platform SE 7 )
Modifying a process builder's ... or the Java process itself. Most error checking is performed by the start() method. It is possible to modify the state of an object so that start() will fail. For example, setting the command attribute to an empty list will not throw an exception unless start() is invoked. Note that this class is not synchronized. If multiple threads access a ProcessBuilder instance ...
🌐
IBM
ibm.com › support › pages › apar › IV77818
IV77818: Multiple failures with java.lang.ProcessBuilder on AIX after applying the APAR IV52649
Other Error Info: Issue can also be manifested as child process doesn't carry environment variables from parent process or missing arguments passed to java.lang.Runtime.exec() or java.lang.ProcessBuilder.start() APIs . In APAR IV52649, for AIX platform, the Java runtime used a system call to identify all the valid open file descriptors and close only those file descriptors. The system macro returns the total number of open file descriptors which is usually the maximum file descriptors in the system as AIX reuse the freed file descriptor before going for a new file descriptor. However, the open file descriptor count need not be the maximum file descriptor in the system always due to a timing window between the allocation of the new file descriptor and freeing an existing file descriptor.
🌐
GitHub
github.com › AdoptOpenJDK › IcedTea-Web › issues › 877
Path processing does not work properly when running ProcessBuilder in CMD /c · Issue #877 · AdoptOpenJDK/IcedTea-Web
July 11, 2022 - Description When executing CMD / C from ProcessBuilder in the Webstart environment of Jdk 8u333, path processing does not work properly. '' Will be included in the first letter. This issue does not occur until JDK8u202. Environment where...
Author   AdoptOpenJDK
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › lang › ProcessBuilder.html
ProcessBuilder (Java SE 9 & JDK 9 )
UnsupportedOperationException - If the operating system does not support the creation of processes. ... Starts a Process for each ProcessBuilder, creating a pipeline of processes linked by their standard output and standard input streams. The attributes of each ProcessBuilder are used to start the respective process except that as each process is started, its standard output is directed to the standard input of the next.
🌐
Leo3418
leo3418.github.io › 2021 › 06 › 20 › java-processbuilder-stdout.html
Properly Handling Process Output When Using Java’s ProcessBuilder - Leo3418's Personal Site
This experiment result suggests that the underlying buffer’s capacity is 65,536 bytes instead of 8192, so the underlying buffer used as the default standard output buffer of a process created by ProcessBuilder is not Java’s BufferedInputStream. Instead, the buffer is a pipe allocated by the operating system. The pipe works in the same way as any pipe created for a Bash command with the | operator, like find -type f *.java -print0 | xargs -0 javac.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › › › java.base › java › lang › ProcessBuilder.html
ProcessBuilder (Java SE 21 & JDK 21)
January 20, 2026 - Modifying a process builder's ... or the Java process itself. Most error checking is performed by the start() method. It is possible to modify the state of an object so that start() will fail. For example, setting the command attribute to an empty list will not throw an exception unless start() is invoked. Note that this class is not synchronized. If multiple threads access a ProcessBuilder instance ...