Home » Java » Running a .py file from Java

Running a .py file from Java

Posted by: admin August 10, 2018 Leave a comment


I am trying to execute a .py file from java code. I move the .py file in the default dir of my java project and I call it using the following code:

    String cmd = "python/";
    String py = "file";
    String run = "python  " +cmd+ py + ".py";

    Process p = Runtime.getRuntime().exec("python  file.py");

Either using variable run, or the whole path or “python file.py” my code is running showing the message build successful total time 0 seconds without execute the file.py. What is my problem here?