🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Process.html
Process (Java Platform SE 8 )
April 21, 2026 - Java™ Platform Standard Ed. 8 ... The ProcessBuilder.start() and Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it.
🌐
Baeldung
baeldung.com › home › java › core java › guide to java.lang.process api
Guide to java.lang.Process API | Baeldung
June 10, 2025 - The Process class provides methods for interacting with these processes, including extracting output, performing input, monitoring the lifecycle, checking the exit status, and destroying (killing) it.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › lang › Process.html
Process (Java SE 21 & JDK 21)
January 20, 2026 - Returns a ProcessHandle for the Process. Process objects returned by ProcessBuilder.start() and Runtime.exec(java.lang.String) implement toHandle as the equivalent of ProcessHandle.of(pid) including the check for a SecurityManager and RuntimePermission("manageProcess").
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-process-class-java
Java.lang.Process class in Java - GeeksforGeeks
February 15, 2023 - Java Collection · Last Updated : 15 Feb, 2023 · The abstract Process class is a process that is, an executing program. Methods provided by the Process are used to perform input, and output, waiting for the process to complete, checking the ...
🌐
DEV Community
dev.to › dbillion › understanding-java-processes-53j0
Understanding Java Processes - DEV Community
May 5, 2024 - This code demonstrates the use of an ExecutorService to manage multiple threads that handle the input and error streams of a process. It’s a practical example of the complexity involved in process management in Java.
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › lang › Process.html
Process (Java SE 9 & JDK 9 )
The class provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.
🌐
DEV Community
dev.to › sadiul_hakim › java-process-api-basics-aml
Java Process API Basics - DEV Community
September 24, 2025 - The Java Process API, available since Java 5 and significantly improved in Java 9, provides a standard way to interact with native operating system processes from within a Java application.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › java_lang_process.htm
Java Process Class
The Java Process class provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › Process.html
Process (Java SE 11 & JDK 11 )
January 20, 2026 - The class provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › concurrency › procthread.html
Processes and Threads (The Java™ Tutorials > Essential Java Classes > Concurrency)
Threads exist within a process — every process has at least one. Threads share the process's resources, including memory and open files. This makes for efficient, but potentially problematic, communication. Multithreaded execution is an essential feature of the Java platform.
🌐
Medium
medium.com › @ayoubtaouam › how-to-build-and-work-with-a-process-in-java-a-beginner-friendly-guide-a1172ed4d6d0
How to Build and Work with a Process in Java: A Beginner-Friendly Guide | by Ayoub Taouam | Medium
August 12, 2025 - In simple terms: A process is a program that is currently running on your computer. When you open your browser or your code editor, each one runs as its own process. Your Java application is also a process.
🌐
GitHub
github.com › rolve › java-processes
GitHub - rolve/java-processes: A small library for creating (and killing!) Java processes · GitHub
JavaProcessBuilder makes it very simple to configure the classpath, the VM args, or the Java executable, if you want them to be different from those of the parent JVM: Process proc = new JavaProcessBuilder(SomeClass.class) .javaHome("/different/java/") .classpath("some-classes.jar") .vmArgs("-ea", "-Xmx8g") .start();
Starred by 4 users
Forked by 2 users
Languages   Java
Top answer
1 of 3
38

http://www.rgagnon.com/javadetails/java-0014.html

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.file.Paths;

public class CmdExec {

public static void main(String args[]) {
    try {
        // enter code here

        Process p = Runtime.getRuntime().exec(
            Paths.get(System.getenv("windir"), "system32", "tree.com /A").toString()
        );

        // enter code here

        try(BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
            String line;

            while ((line = input.readLine()) != null) {
                System.out.println(line);
            }
        }

    } catch (Exception err) {
        err.printStackTrace();
    }
  }
}

You can get the local path using System properties or a similar approach.

http://download.oracle.com/javase/tutorial/essential/environment/sysprop.html

2 of 3
31

The Java Class Library represents external processes using the java.lang.Process class. Processes can be spawned using a java.lang.ProcessBuilder:

Process process = new ProcessBuilder("processname").start();

or the older interface exposed by the overloaded exec methods on the java.lang.Runtime class:

Process process = Runtime.getRuntime().exec("processname");

Both of these will code snippets will spawn a new process, which usually executes asynchronously and can be interacted with through the resulting Process object. If you need to check that the process has finished (or wait for it to finish), don't forget to check that the exit value (exit code) returned by process.exitValue() or process.waitFor() is as expected (0 for most programs), since no exception is thrown if the process exits abnormally.

Also note that additional code is often necessary to handle the process's I/O correctly, as described in the documentation for the Process class (emphasis added):

By default, the created subprocess does not have its own terminal or console. All its standard I/O (i.e. stdin, stdout, stderr) operations will be redirected to the parent process, where they can be accessed via the streams obtained using the methods getOutputStream(), getInputStream(), and getErrorStream(). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, or even deadlock.

One way to make sure that I/O is correctly handled and that the exit value indicates success is to use a library like jproc that deals with the intricacies of capturing stdout and stderr, and offers a simple synchronous interface to run external processes:

ProcResult result = new ProcBuilder("processname").run();

jproc is available via maven central:

<dependency>
      <groupId>org.buildobjects</groupId>
      <artifactId>jproc</artifactId>
      <version>2.5.1</version>
</dependency>
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › core › process-api1.html
6 Process API - Java
October 20, 2025 - Number of processes: 3 Start 12401, /bin/sh -c grep -c "java" * Start 12403, /bin/sh -c grep -c "Process" * Start 12404, /bin/sh -c grep -c "onExit" * Press enter to continue ...
🌐
Ongres
ongres.com › blog › java-processes-and-streams
OnGres | Java, Processes and Streams
Still, the implementation mimics the one used by Apache Commons Exec when it comes to handle reading and writing of the process' stdin, stdout and stderr, with 3 additional threads running in background. JProc is also a modern library, supporting Java 1.7+ and provides a fluent API that is really nice to use.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.process
Process Class (Java.Lang) | Microsoft Learn
The class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › Process.html
Process (Java SE 17 & JDK 17)
October 20, 2025 - Returns a ProcessHandle for the Process. Process objects returned by ProcessBuilder.start() and Runtime.exec(java.lang.String) implement toHandle as the equivalent of ProcessHandle.of(pid) including the check for a SecurityManager and RuntimePermission("manageProcess").
🌐
Jfeatures
jfeatures.com › blog › jps
Find all the Java processes running on your machine
May 28, 2021 - For rest of the blog post we will use jps on this process. java -XX:ConcGCThreads=6 -Xmx256m -Xms8m -Xss256k Test argument1 argument2
🌐
Baeldung
baeldung.com › home › java › core java › guide to java.lang.processbuilder api
Guide to java.lang.ProcessBuilder API | Baeldung
November 26, 2025 - When working with file paths that contain spaces, we pass the full path as a single argument string. We let ProcessBuilder manage the necessary escaping and avoid breaking the path into separate parts. Java 9 introduced the concept of pipelines to the ProcessBuilder API: