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 ... 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 ...
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 - 8 ... Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
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.
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 ...
GeeksforGeeks
geeksforgeeks.org › java › java-lang-processbuilder-class-java
Java.lang.ProcessBuilder class in Java - GeeksforGeeks
January 14, 2022 - Key = PATH, Value = /usr/bin:/bin:/usr/sbin:/sbin Key = JAVA_MAIN_CLASS_14267, Value = ProcessBuilderDemo Key = J2D_PIXMAPS, Value = shared Key = SHELL, Value = /bin/bash Key = JAVA_MAIN_CLASS_11858, Value = org.netbeans.Main Key = USER, Value = abhishekverma Key = TMPDIR, Value = /var/folders/9z/p63ysmfd797clc0468vvy4980000gn/T/ Key = SSH_AUTH_SOCK, Value = /private/tmp/com.apple.launchd.uWvCfYQWBP/Listeners Key = XPC_FLAGS, Value = 0x0 Key = LD_LIBRARY_PATH, Value = /Library/Java/JavaVirtualMachines /jdk1.8.0_121.jdk/Contents/Home/jre/lib/ amd64:/Library/Java/JavaVirtualMachines/jdk1.8.0_121
ZetCode
zetcode.com › java › processbuilder
Java ProcessBuilder - creating processes in Java
May 1, 2025 - In order to run a command on Windows machine, we could use the following: processBuilder.command("cmd.exe", "/c", "ping -n 3 google.com"). ... The process is lauched with start. try (var reader = new BufferedReader( new InputStreamReader(process.getInputStream()))) { With the getInputStream ...
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
* will never affect previously started processes or the Java process · * itself. * * <p>Most error checking is performed by the {@link #start()} method. * It is possible to modify the state of an object so that {@link · * #start()} will fail. For example, setting the command attribute to · * an empty list will not throw an exception unless {@link #start()} * is invoked. * * <p><strong>Note that this class is not synchronized.</strong> * If multiple threads access a {@code ProcessBuilder} instance ·
Author bpupadhyaya
Baeldung
baeldung.com › home › java › core java › guide to java.lang.process api
Guide to java.lang.Process API | Baeldung
June 10, 2025 - ProcessBuilder builder = new ProcessBuilder("notepad.exe"); Process process = builder.start(); assertFalse(process.waitFor(1, TimeUnit.SECONDS)); We can see from the above example that for the current thread to continue execution, it will keep ...
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
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › ProcessBuilder.Redirect.html
ProcessBuilder.Redirect (Java Platform SE 8 )
April 21, 2026 - Java™ Platform Standard Ed. 8 · Prev Class · Next Class · Frames · No Frames · All Classes · Summary: Nested | Field | Constr | Method · Detail: Field | Constr | Method · compact1, compact2, compact3 · java.lang · java.lang.Object · java.lang.ProcessBuilder.Redirect ·
Java Tips
javatips.net › blog › java-processbuilder-example
Java ProcessBuilder Example
April 29, 2016 - package com.test; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class JavaProcessBuilderExample { /** * In this Java ProcessBuilder Example, We are showing how to run external * programs and operating system process */ public static void main(String[] args) throws IOException { List<String> command = new ArrayList<String>(); // For linux command.add("uptime"); // For windows // command.add("notepad.exe"); // command.add("C:\\file.txt"); ProcessBuilder processbuilder = new ProcessBuilder(command); // Redirect output to this file.
Java Tips
javatips.net › api › java.lang.processbuilder
Java Examples for java.lang.ProcessBuilder - Javatips.net
Example 49 · @Test public void testMain() throws Exception { Process process = new ProcessBuilder(ImmutableList.of(Paths.get(System.getProperty("java.home")).resolve("bin/java").toString(), "-cp", System.getProperty("java.class.path"), Main.class.getName())).redirectError(Redirect.PIPE).redirectOutput(Redirect.PIPE).start(); process.waitFor(); String err = new String(ByteStreams.toByteArray(process.getErrorStream()), UTF_8); assertThat(err).contains("Usage: google-java-format"); assertThat(process.exitValue()).isEqualTo(0); } Example 50 ·
Tutorialspoint
tutorialspoint.com › java › lang › java_lang_processbuilder.htm
Java ProcessBuilder Class
package com.tutorialspoint; import ... list.add("notepad.exe"); // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // get the command list System.out.println(pb.command()); } }...
Top answer 1 of 13
105
Read from the InputStream. You can append the output to a StringBuilder:
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ( (line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
String result = builder.toString();
2 of 13
42
As of Java 9, we finally have a one liner:
ProcessBuilder pb = new ProcessBuilder("pwd");
Process process = pb.start();
String result = new String(process.getInputStream().readAllBytes());
Android Developers
developer.android.com › api reference › processbuilder
ProcessBuilder | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体