pass data result from python to Java variable by processbuilder
<p>I used process builder to run a python script from java. and i can sent the data from Java to python variable ( import sys to get data from Java) . and print out the python result in java.
for example: </p>

<pre><code>public static void main(String a[]){
try{

int number1 = 100;
int number2 = 200;
String searchTerm="water";

ProcessBuilder pb = new ProcessBuilder("C:/Python27/python","D://my_utils.py",""+number1,""+number2,""+searchTerm);
Process p = pb.start();

BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream()));

System.out.println(".........start   process.........");  
String line = "";     
while ((line = bfr.readLine()) != null){
    System.out.println("Python Output: " + line);
}
System.out.println("........end   process.......");


}catch(Exception e){System.out.println(e);}
}
}
</code></pre>

<p>However, I do not know how to get back the result from python and pass the result to <strong>JAVA Variable</strong> for further use. How to do that?
I have issue with passing a list as a method argument in JAVA.
[![enter image description here][1]][1]
[![enter image description here][2]][2]
How to pass the variable (<strong>return variable</strong> in   def MatchSearch() in python) to the <strong>JAVA VARIABLE</strong>?  </p>

<p>As far as I am aware, you can't do that with ProcessBuilder. You can print your variable to the output and let Java interpret it. Or you can use some API that is connecting Java and Python stronger (for example <a href="http://www.jython.org/" rel="nofollow">Jython</a>).</p>

java python json processbuilder sys