NOTE: Path of python.exe has already been set
I am trying to create a Java program that passes the variable args
(or any other variable) to a Python script.
import java.io.*;
public class PythonCallTest{
public static void main (String[] args){
String s = null;
Runtime r = Runtime.getRuntime();
try{
Process p = r.exec("cmd /c python ps.py+",args);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
while ((s = stdInput.readLine()) != null){
System.out.println(s);
}
while ((s = stdError.readLine()) != null){
System.out.println(s);
}
System.exit(0);
}
catch(IOException ioe){
ioe.printStackTrace();
System.exit(-1);
}
}
}
The program compiles but when I run it with
java PythonCallTest sender-ip=10.10.10.10
I get the error
'python' is not recognized as an internal or external command, operable program or batch file.
How do I properly concatenate the string in r.exec("cmd /c python ps.py+",args)
EDIT
If I execute the following
Process p = r.exec("cmd /c python ps.py sender-ip=10.251.22.105");
Then the program works. The path for python.exe has already been set. I just need to know how to add args to r.exec, i.e how to concatenate cmd /c python ps.py with args