You don't need to include spaces. The ProcessBuilder will deal with that for you. Just pass in your arguments one by one, without space:

ProcessBuilder pb = new ProcessBuilder(
    dir + "library/crc",
    "-s",
    fileName,
    addressRanges);
Answer from assylias on Stack Overflow
🌐
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 ... API, we may need to pass arguments that contain spaces, such as strings with multiple words or file paths under directories....
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java processbuilder command list
Java ProcessBuilder command() Method
September 1, 2008 - The Java ProcessBuilder command(List<String> command) method sets this process builder's operating system program and arguments. This method does not make a copy of the command list.
🌐
Mkyong
mkyong.com › home › java › java processbuilder examples
Java ProcessBuilder examples - Mkyong.com
January 19, 2019 - Pinging google.com [172.217.166.142] ... Exited with error code : 0 · In above example 1.1, the process.getInputStream is “blocking”, it is better to start a new Thread for the reading process, so that it won’t block other tasks. ... package com.mkyong.process; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.List; import java.util.concurrent.*; import java.util.stream.Collectors; public class ProcessBuilderExample2 { public static ...
🌐
Coderanch
coderanch.com › t › 709883 › java › Add-parameters-ProcessBuilder
Add parameters to ProcessBuilder (Java in General forum at Coderanch)
May 17, 2019 - It's missing the 'sh' part the first one has). ... Yes for all the three String[] cmd = {"sh test.sh", "user", "pw"}; String[] cmd = {"/c/users/lia/desktop/sh test.sh", "user", "pw"}; String[] cmd = {"/c/users/lia/desktop/test.sh", "user", "pw"}; it is not working ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › ProcessBuilder.html
ProcessBuilder (Java Platform SE 8 )
3 weeks ago - Each ProcessBuilder instance manages a collection of process attributes. The start() method creates a new Process instance with those attributes. The start() method can be invoked repeatedly from the same instance to create new subprocesses with identical or related attributes. Each process builder manages these process attributes: a command, a list of strings which signifies the external program file to be invoked and its arguments...
🌐
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
🌐
Dot Net Perls
dotnetperls.com › process-java
Java - Process, ProcessBuilder Examples - Dot Net Perls
September 16, 2024 - Note 2 Sometimes a specific browser is standardized upon in an organization. This command would work there. import java.io.IOException; import java.util.ArrayList; public class Program { public static void main(String[] args) throws IOException { ProcessBuilder b = new ProcessBuilder(); // Create ...
🌐
Tabnine
tabnine.com › home page › code › java › java.lang.processbuilder
java.lang.ProcessBuilder.command java code examples | Tabnine
*/ private int executeHadoopCm... procBuilder = createProcessBuilder(); List<String> cmd = new ArrayList<>(); cmd.add(hadoopHome + "/bin/hadoop"); cmd.addAll(Arrays.asList(args)); procBuilder.command(cmd); log().info("Execute: " + procBuilder.command()); return watchProcess(procBuilder.start()); }...
Find elsewhere
🌐
TechBeamers
techbeamers.com › java-processbuilder-example-to-run-a-bat-file-with-arguments
Java ProcessBuilder example to run a bat file with arguments
February 1, 2025 - System.out.println(" "); System.out.println("==========Arguments Passed From Command line==========="); for (String s: args) { // Iterate through String array in Java (args list) System.out.println(s); } System.out.println("============================"); System.out.println(" "); final StringBuffer sb = new StringBuffer(); int processComplete = -1; ProcessBuilder pb = new ProcessBuilder(args); pb.redirectErrorStream(true); try { final Process process = pb.start(); final InputStream is = process.getInputStream(); // the background thread watches the output from the process new Thread(new Runnab
🌐
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.
🌐
Thedeveloperblog
thedeveloperblog.com › processbuilder
Java ProcessBuilder Examples: Start Process, EXE
Java program that uses ProcessBuilder import java.io.IOException; import java.lang.ProcessBuilder; public class Program { public static void main(String[] args) throws IOException { String folder = "C:\\Program Files\\Adobe\\Adobe Photoshop CC\\"; String exe = "photoshop.exe"; // Create and ...
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › ProcessBuilder.html
ProcessBuilder (Java SE 11 & JDK 11 )
January 20, 2026 - The returned value may be null -- this 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. ... Sets this process builder's working directory. Subprocesses subsequently started by this object's start() method will use this as their working directory. The argument may be null -- this 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.
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8263697
Safer Process Launch by ProcessBuilder and Runtime.exec
March 24, 2022 - The motivation for these changes ... how the application to use ProcessBuilder to avoid or mitigate those risks. To run a java Hello program with a string containing spaces use separate arguments....
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › ProcessBuilder.html
ProcessBuilder (Java Platform SE 7 )
Each ProcessBuilder instance manages a collection of process attributes. The start() method creates a new Process instance with those attributes. The start() method can be invoked repeatedly from the same instance to create new subprocesses with identical or related attributes. Each process builder manages these process attributes: a command, a list of strings which signifies the external program file to be invoked and its arguments...
🌐
Tutorialspoint
tutorialspoint.com › java › lang › processbuilder_start.htm
Java ProcessBuilder start() Method
Now using start() method, we've started the process. package com.tutorialspoint; import java.io.IOException; public class ProcessBuilderDemo { public static void main(String[] args) { // create a new list of arguments for our process String[] list = {"explorer.exe"}; // create the process builder ...
🌐
OpenJDK
openjdk.org › jeps › 8263697
JEP draft: Safer Process Launch by ProcessBuilder and Runtime.exec
The motivation for these changes ... or untrusted sources. The example below show how the application to use ProcessBuilder to avoid or mitigate those risks. To run a java Hello program with a string containing spaces use separate arguments....
🌐
Tutorialspoint
tutorialspoint.com › java › lang › java_lang_processbuilder.htm
Java ProcessBuilder Class
package com.tutorialspoint; import ... { 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()); ...
🌐
Classpath
developer.classpath.org › doc › java › lang › ProcessBuilder.html
ProcessBuilder (GNU Classpath 0.95 Documentation)
By default, this is the working ... of the program binary followed by an arbitrary number of arguments. For example, find -type f invokes the find binary with the arguments "-type" and "f"....
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.processbuilder
ProcessBuilder Class (Java.Lang) | Microsoft Learn
Each ProcessBuilder instance manages a collection of process attributes. The #start() method creates a new Process instance with those attributes. The #start() method can be invoked repeatedly from the same instance to create new subprocesses with identical or related attributes. Each process builder manages these process attributes: ... <li>a command, a list of strings which signifies the external program file to be invoked and its arguments, if any.