This is the first time I am trying python in java. I am trying to execute python script from my code as follows.
Process process = Runtime.getRuntime().exec("python C:\\Users\\username\\Desktop\\demo\\filename.py");
But I am getting following exception
"Cannot run program "python": CreateProcess error=2, The system cannot find the file specified"
I have installed python. I am not sure why the file is not found. I tried to follow this link but it did not solve my issue.
Thanks in advance.
Edit 1
I tried the sample code given by "Viacheslav Vedenin", it worked when I executed my java(servlet) program. But when I ran the same function from JSP button click event, it did not work. It gave me following error
java.io.IOException: Cannot run program "python": CreateProcess error=2, The system cannot find the file specified
Please help me to resolve this issue.
-
You can add to the path Enviroment Variable the path of python soo thenyou will be able to execute a python commandMaQuiNa1995– MaQuiNa19952017年06月30日 11:20:37 +00:00Commented Jun 30, 2017 at 11:20
1 Answer 1
Try to use full path to python, for example
Process process = Runtime.getRuntime().exec("C:\\Python\\python.exe
C:\\Users\\username\\Desktop\\demo\\filename.py");
2 Comments
Explore related questions
See similar questions with these tags.