I create simple python statement my_utils.py
def adder(a, b):
c=a+b
return c
I would like to assign value to python in Java.
public class ParameterPy {
public static void main(String a[]){
try{
int number1 = 100;
int number2 = 200;
ProcessBuilder pb = new ProcessBuilder("C:/Python27/python","D://my_utils.py",""+number1,""+number2);
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);}
}
}
However, process builder is not able to pass the parameter value to a, b in python and display the result.
How to give the parameter value to python? If the numeric value is worked? How about if I pass the non-numeric value such as a string to python
def str(myWord):
if myWord=="OK":
print "the word is OK."
else:
print " the word is not OK."