How to Run a Python file from Java using an Absolute Path?

后端 未结 2 598
终归单人心
终归单人心 2021-01-15 01:19

I want to run a python script called, for example foo. And I have the absoulute path, lets say: /Users/me/pythonscripts/

I have tried running:

St         


        
2条回答
  •  猫巷女王i
    2021-01-15 01:59

    this work for me

        public static void main(String[] args)  throws IOException{
    
        Runtime runtime = Runtime.getRuntime();
        Process p1 = runtime.exec("D:\\programs\\Anaconda3\\Scripts\\spyder.exe \"C:\\Users\\Al-Hanouf\\codes\\PageRank.py\"");
        System.out.print("is process alive = "+p1.isAlive());
    
    }
    

提交回复
热议问题