Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › ProcessBuilder.html
ProcessBuilder (Java Platform SE 8 )
April 21, 2026 - Java™ Platform Standard Ed. 8 ... This class is used to create operating system processes. Each ProcessBuilder instance manages a collection of process attributes. The start() method creates a new Process instance with those attributes.
ZetCode
zetcode.com › java › processbuilder
Java ProcessBuilder - creating processes in Java
May 1, 2025 - Learn how to create and manage operating system processes in Java using ProcessBuilder. This tutorial covers executing commands, handling process input/output, and optimizing system interactions in Java applications.
Mkyong
mkyong.com › home › java › java processbuilder examples
Java ProcessBuilder examples - Mkyong.com
January 19, 2019 - ProcessBuilder processBuilder = new ProcessBuilder(); // -- Linux -- // Run a shell command processBuilder.command("bash", "-c", "ls /home/mkyong/"); // Run a shell script processBuilder.command("path/to/hello.sh"); // -- Windows -- // Run a command processBuilder.command("cmd.exe", "/c", "dir C:\\Users\\mkyong"); // Run a bat file processBuilder.command("C:\\Users\\mkyong\\hello.bat"); Process process = processBuilder.start(); 1.1 Run an external ping command to ping a website 3 times, and display the output. ... package com.mkyong.process; import java.io.BufferedReader; import java.io.IOExce
GeeksforGeeks
geeksforgeeks.org › java › java-lang-processbuilder-class-java
Java.lang.ProcessBuilder class in Java - GeeksforGeeks
January 14, 2022 - 3. ProcessBuilder directory(File directory): This method sets the process builder's working directory. Subprocesses subsequently started by object's start() method will use it as their working directory. The argument may be null - which means to use the working directory of the current Java process, usually, the directory named by the system property user.dir, as the working directory of the child process.
Tutorialspoint
tutorialspoint.com › java › lang › java_lang_processbuilder.htm
Java ProcessBuilder Class
Following is the declaration for java.lang.ProcessBuilder class − ... The following example shows the usage of ProcessBuilder command() method. In this program, we've created a list of Strings and added notepad.exe to it. Using that list, we've initialized a ProcessBuilder instance. Now using command() method, we've printed the underlying operating system command name and other details. package com.tutorialspoint; import java.util.ArrayList; import java.util.List; public class ProcessBuilderDemo { public static void main(String[] args) { // create a new list of arguments for our process List<String> list = new ArrayList<String>(); list.add("notepad.exe"); // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // get the command list System.out.println(pb.command()); } }
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › class-use › ProcessBuilder.html
Uses of Class java.lang.ProcessBuilder (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8
Baeldung
baeldung.com › home › java › core java › guide to java.lang.process api
Guide to java.lang.Process API | Baeldung
June 10, 2025 - @Test void givenAProcess_whenUsingWaitFor_thenNoExceptionThrown() { // Code that interacts with a process should not throw IllegalMonitorStateException. assertDoesNotThrow(() -> { Process process = new ProcessBuilder("notepad.exe").start(); int exitCode = process.waitFor(); }); } In summary, we can fix the IllegalMonitorStateException: Current thread is not owner of the lock! when dealing with java.lang.Process, by using Process.waitFor() to wait for the process to complete.
Javatpoint
javatpoint.com › processbuilder-in-java
ProcessBuilder in Java - Javatpoint
ProcessBuilder in Java with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
Javatpoint
javatpoint.com › java-processbuilder-example
Java ProcessBuilder Example - Javatpoint
Java ProcessBuilder Example with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
GitHub
github.com › bpupadhyaya › openjdk-8 › blob › master › jdk › src › share › classes › java › lang › ProcessBuilder.java
openjdk-8/jdk/src/share/classes/java/lang/ProcessBuilder.java at master · bpupadhyaya/openjdk-8
import java.util.Map; · /** * This class is used to create operating system processes. * * <p>Each {@code ProcessBuilder} instance manages a collection · * of process attributes.
Author bpupadhyaya
Rip Tutorial
riptutorial.com › using the processbuilder class
Java Language Tutorial => Using the ProcessBuilder class
List<String> cmds = new ArrayList<>(); cmds.add("Add.exe"); //the name of the application to be run cmds.add("1"); //the first argument cmds.add("5"); //the second argument ProcessBuilder pb = new ProcessBuilder(cmds); //Set the working directory of the ProcessBuilder so it can find the .exe //Alternatively you can just pass in the absolute file path of the .exe File myWorkingDirectory = new File(yourFilePathNameGoesHere); pb.workingDirectory(myWorkingDirectory); try { Process p = pb.start(); } catch (IOException e) { e.printStackTrace(); }
Dot Net Perls
dotnetperls.com › process-java
Java - Process, ProcessBuilder Examples - Dot Net Perls
September 16, 2024 - ProcessBuilder p = new ProcessBuilder(); // Use command "notepad.exe" and open the file. p.command("notepad.exe", "C:\\file.txt"); p.start(); } } In this example we invoke a specific executable at a known location on the computer. We concat a folder path and an executable name.
Top answer 1 of 10
31
The Runtime.getRuntime().exec() approach is quite troublesome, as you'll find out shortly.
Take a look at the Apache Commons Exec project. It abstracts you way of a lot of the common problems associated with using the Runtime.getRuntime().exec() and ProcessBuilder API.
It's as simple as:
String line = "myCommand.exe";
CommandLine commandLine = CommandLine.parse(line);
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
int exitValue = executor.execute(commandLine);
2 of 10
27
Yes it is possible using ProcessBuilder.
ProcessBuilder example:
import java.io.*;
import java.util.*;
public class CmdProcessBuilder {
public static void main(String args[])
throws InterruptedException,IOException
{
List<String> command = new ArrayList<String>();
command.add(args[0]);
ProcessBuilder builder = new ProcessBuilder(command);
Map<String, String> environ = builder.environment();
final Process process = builder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("Program terminated!");
}
}
Check these examples:
http://www.rgagnon.com/javadetails/java-0014.html
http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html
Tutorialspoint
tutorialspoint.com › java › lang › processbuilder_command.htm
Java ProcessBuilder command() Method
Using that list, we've initialized a ProcessBuilder instance. Now using command() method, we've printed the underlying operating system command name and other details. package com.tutorialspoint; import java.util.ArrayList; import java.util.List; public class ProcessBuilderDemo { public static void main(String[] args) { // create a new list of arguments for our process List<String> list = new ArrayList<>(); list.add("explorer.exe"); // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // get the command list System.out.println(pb.command()); } }
CodingTechRoom
codingtechroom.com › tutorial › java-java-lang-processbuilder-api
Mastering the Java Lang ProcessBuilder API: A Comprehensive Guide - CodingTechRoom
Understanding how to use the ... effectively. This tutorial will guide you through the ins and outs of the API, enabling you to create robust applications that interact seamlessly with the system....