You can check the documentation ProcessBuilderin Sunoracle , but basically you can run the interpreter for the scripting language and pass the script you want to run it.
For example, let's say you have a script in /home/myuser/py_script.py, and pythonis located in/usr/bin/
class ProcessRunner
{
public static void main(String [] args)
{
ProcessBuilder pb = new ProcessBuilder("/usr/bin/python", "/home/myuser/py_script.py");
Process p = pb.start();
}
}
An extremely simple example, you can become a favorite in changing the working directory and changing the environment.
You can also build ProcessBuilderwith an array Stringor subtype List<String>. The first item in the list should be the program / executable that you want to run, and all of the following items are the arguments of the program.
String pbCommand[] = { "/usr/bin/python", "/home/myuser/py_script.py" };
ProcessBuilder pb = new ProcessBuilder(pbCommand);
Process p = pb.start();
source
share