I'm attempting to run a Python script using Java code in Intellij IDEA:
String commandString = "python /home/.../mypythonscript.py arg1 arg2";
try {
Process process = Runtime.getRuntime().exec(commandString);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
} catch(IOException e) {
System.out.println(e.getMessage());
The Python script outputs a single String, and works great when I run it from my Ubuntu Linux terminal. However, using the above Java to run the Python script returns an error message:
Failed to run Python Script: Cannot run program "python": error=2, No such file or directory.
The file path is correct (the path and arguments I give are identical to what I used to run the Python script in the terminal), and I've set the script permissions to 777. In Intellij, I've also gone to File>Settings>Appearance & Behavior>Path Variables and added a path to the folder that contains the Python script (it's being held in a folder for Pycharm projects). However, I'm still getting the error.
Any help would be much appreciated!