Just give them as separate strings in the array, instead of combining the last two into "val_31 val_32":

String[] command = {"script.py", "run",
                    "-arg1", "val1", 
                    "-arg2", "val2" ,          
                    "-arg3" , "val_31", "val_32",
       };

Otherwise it will escape the space in between val_31 and val_32 because you are telling it that they're a single parameter. Incidentally, you can also use the varargs constructor and skip having to create an array, if you want:

ProcessBuilder probuilder = new ProcessBuilder( "script.py", "run",
                    "-arg1", "val1", 
                    "-arg2", "val2" ,          
                    "-arg3" , "val_31", "val_32");
Answer from David Robinson on Stack Overflow
🌐
Quora
quora.com › How-do-I-call-python-function-using-process-builder
How to call python function using process builder - Quora
Answer (1 of 2): [code]Process p = new ProcessBuilder("{{ python-command }}", "{{ arguments }}").start(); [/code]Your python file, file.py: [code]def foo(): //your prof def main(): if argv[0]=="foo": foo() if __name__ == "__main__": main() [/code]{{ python-command }} will be...
Discussions

Running python from Java using Process Builder - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... For an existing Java code that I want to extend, I need to run a python code from within Java. I am using Process builder for this: More on stackoverflow.com
🌐 stackoverflow.com
April 1, 2016
python - Building a process with ProcessBuilder from a .py script? - Stack Overflow
As part of some coursework I'm doing, I need to use ProcessBuilder to simulate an OS process scheduler - with Python scripts as processes. The issue is I can't get my ProcessBuilder to recognise a ... More on stackoverflow.com
🌐 stackoverflow.com
Running a python code using process builder Java - Stack Overflow
I need some help. I am trying to run a python script called mantime.py from a directory. I've tried to google it and found several ways to do it. Yet, I still got 2 as the exit value, which I expec... More on stackoverflow.com
🌐 stackoverflow.com
Java/python using processBuilder - Stack Overflow
Good evening all, am running a python script inside java using processBuilder. the python script returns a list and i dont know how to get it java and use it since all i can do for the moment with process builder is print errors or outputs. is it possible to get the list in java as well. More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 5
3

Usually when executing commands using ProcessBuilder, PATH variable is not taken into consideration. Your python C:/Machine_Learning/Text_Analysis/Ontology_based.py is directly working in your CMD shell because it can locate the python executable using the PATH variable. Please provide the absolute path to python command in your Java code. In below code replace <Absolute Path to Python> with the path to python command and its libraries. Usually it will something like C:\Python27\python in Windows by default

package text_clustering;

import java.io.*;

public class Similarity {

    /**
     * 
     * @param args
     * 
     */
    public static void main(String[] args){
        try{
            String pythonPath = "C:/Machine_Learning/Text_Analysis/Ontology_based.py";
            //String pythonExe = "C:/Users/AppData/Local/Continuum/Anaconda/python.exe";
            ProcessBuilder pb = new ProcessBuilder(Arrays.asList("<Absolute Path to Python>/python", pythonPath));
            Process p = pb.start();

            BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = "";
            System.out.println("Running Python starts: " + line);
            int exitCode = p.waitFor();
            System.out.println("Exit Code : "+exitCode);
            line = bfr.readLine();
            System.out.println("First Line: " + line);
            while ((line = bfr.readLine()) != null){
                System.out.println("Python Output: " + line);


            }

        }catch(Exception e){System.out.println(e);}
    }

}
2 of 5
0

Reading from stdin returns null when the script is killed/dies. Do a Process#waitFor and see what the exitValue is. If it isn't 0 then it's highly probable that your script is dying.

I'd try making it work with a dumb script that only writes a value. Make sure that you print all error information from python.

🌐
Stack Overflow
stackoverflow.com › questions › 35685056 › running-python-from-java-using-process-builder
Running python from Java using Process Builder - Stack Overflow
April 1, 2016 - For an existing Java code that I want to extend, I need to run a python code from within Java. I am using Process builder for this: ProcessBuilder pb = new ProcessBuilder("python", "/directoryp...
🌐
Helicaltech
helicaltech.com › blog › ways to execute python code from java
Ways to Execute Python Code From Java - Helical IT Solutions Pvt Ltd
Big Data Consulting Services, Big Data Analytics - Helical IT solutions Pvt Ltd
There are many ways to execute Python code from with in Java. In case if your project has requirement to execute Python code from Java, here are few code samples that I have collected from Internet. First way is using Jython: 3. Invoking native python interpreter using Java Helical IT Solutions Pvt Ltd offers Jaspersoft consulting, Pentaho consulting, Talend consulting &amp; big data consulting services. Helical IT Solutions Pvt Ltd, based out of Hyderabad India, is an IT company specializing in Data Warehousing, Business Intelligence and Big Data Analytics Services.
Rating: 4.4 ​
🌐
Stack Overflow
stackoverflow.com › questions › 79921476 › building-a-process-with-processbuilder-from-a-py-script
python - Building a process with ProcessBuilder from a .py script? - Stack Overflow
I don't have enough experience to diagnose the issue any further - beyond verifying that the filepath used, passed into the function by a parameter, is in fact correct (which it is; I found the pre-written code that creates the relevant .py at runtime, and that it makes it in an @tempdir directory and sends the filepath). ... @Override public void run() { System.out.println("Working Directory = " + PCB.getProcessPath()); // debug print; running = true; PCB.callState("running"); ProcessBuilder Build = new ProcessBuilder("python", PCB.getProcessPath()); Process prcss = null; try { prcss = Build.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-the-builder-pattern-in-python-a-practical-guide-for-devs
How to Use the Builder Pattern in Python – A Practical Guide for Developers
January 28, 2026 - If you need to set up an object ... calls in a particular sequence, a builder can enforce and simplify this process. You need to create different variations of an object. Builders can create different representations of the same type, like different SQL query types or different HTTP request configurations. ... Your objects are simple. If a regular constructor with 2-3 parameters works fine, don't add builder complexity. Python's keyword ...
🌐
ROS Answers
answers.ros.org › question › 325790 › error-when-running-python-script-with-processbuilder-rospkgcommonresourcenotfound-rosgraph
Error when running python script with ProcessBuilder()- rospkg.common.ResourceNotFound: rosgraph - ROS Answers archive
June 14, 2019 - I want to run a python script with ProcessBuilder(). This is my code: new ProcessBuilder().inheritIO().command("/usr/bin/python", System.getProperty("user.dir")+"/WebRoot/result.py").start();
Find elsewhere
🌐
GitHub
gist.github.com › zhugw › 8d5999a3b2f6aef3ca21f53ca82d054c
Java invoke python script · GitHub
Java invoke python script. GitHub Gist: instantly share code, notes, and snippets.
🌐
Stack Overflow
stackoverflow.com › questions › 31225697 › running-a-python-code-using-process-builder-java
Running a python code using process builder Java - Stack Overflow
CopyProcessBuilder("/usr/bin/python","/Users/ab/Downloads/ManTIME/mantime.py","-ppp","test",inputDir.getAbsolutePath(),"i2b2"); pb.directory(/myToolsDir)
🌐
Stack Overflow
stackoverflow.com › questions › 27955622 › java-python-using-processbuilder
Java/python using processBuilder - Stack Overflow
From your scenario, you are looking for inter process communication. You can achieve this using shared file. Your python script will write the output in text file, and your java program will read the same file.
🌐
Processing Forum
forum.processing.org › two › discussion › 24555 › run-python-from-processing-execute-python-file.html
Run Python from Processing. (Execute Python File) - Processing 2.x and 3.x Forum
Execute python from Processing How to run python file from processing. I tried Launch() already. It doesn't do anything. Then i tried exec and process builder. both throw me back with "Unhandled exception type IOException". Any help ? ... And you are trying to do this in JavaScript Mode -- i.e.
🌐
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 - So when I try and do this: It finished instantly with no output. Whereas this: Returns '/usr/bin/python' which is the path to python 2.7 I have tried many, many different variation, of which here are a few: And countless more. They all have also been tried using 'runtime.getruntime().exec'. Why is the process builder different to normal terminal?
🌐
Stack Overflow
stackoverflow.com › questions › tagged › processbuilder
Newest 'processbuilder' Questions - Page 2 - Stack Overflow
November 11, 2022 - My use case is to use process builder in java springboot to open a test url in google chrome. I have explored various commands to do the same but not able to achieve a desired result. I have explored ... ... I am using the following Java code to execute a MySQL command that imports data from a source file: String command = String.format("%s -h %s -P%s -u%s -p%s -D %s < %s", mysqlCommand, ip, ... ... We are using ProcessBuilder in Java to execute Python program on a Linux machine.
🌐
Refactoring.Guru
refactoring.guru › home › design patterns › builder › python
Builder in Python / Design Patterns
January 1, 2026 - """ def build_minimal_viable_product(self) -> None: self.builder.produce_part_a() def build_full_featured_product(self) -> None: self.builder.produce_part_a() self.builder.produce_part_b() self.builder.produce_part_c() if __name__ == "__main__": """ The client code creates a builder object, passes it to the director and then initiates the construction process.
🌐
Visual Components
forum.visualcomponents.com › process modeling
How do I create a process flow in Python? - Process Modeling - Visual Components - The Simulation Community
May 31, 2022 - Hello, I am trying to model a process by using solely Python scripts. Could you advise me on what specifc class I could use to define and program a process and how would I connect several processes into a flow and match with a flow group? What could be the key words I need to search after in ...
🌐
GitHub
github.com › csgoh › processpiper
GitHub - csgoh/processpiper: An open source python library to generate business process diagram using code or plain text. · GitHub
ProcessPiper is an open source python library to generate business process diagram using python code or PiperFlow syntax. This is a sample code to generate a business process diagram using PiperFlow syntax. from processpiper.text2diagram import ...
Starred by 193 users
Forked by 14 users
Languages   Python
🌐
Stack Overflow
stackoverflow.com › tags › processbuilder
Newest 'processbuilder' Questions - Stack Overflow
I have a simple exe file in path D:\this\is\my\path which is what i'm putting to my processbuilder i.e ProcessBuilder builder = new ProcessBuilder(); builder.directory(new File(myPath))... ... [update] Sorry guys! processbuilder works fine, but it was my other problem. It was just that I didn't run it in a virtual environment with the libraries needed for my python code installed...