Java da Python Script Çağırmak Çalıştırmak

public static  void main(String args[]) throws IOException {
  Runtime rt = Runtime.getRuntime();
  String[] commands = {"python",CallAnotherProgram.class.getClassLoader().getResource("script.py").getPath()};
  Process proc = rt.exec(commands);

  BufferedReader stdInput = new BufferedReader(new 
       InputStreamReader(proc.getInputStream()));

  BufferedReader stdError = new BufferedReader(new 
       InputStreamReader(proc.getErrorStream()));

  String s = null;
  while ((s = stdInput.readLine()) != null) {
      System.out.println(s);
  }


  while ((s = stdError.readLine()) != null) {
      System.out.println(s);
  }
}

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *