Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. package org.norbert;
  2.  
  3. import java.io.*;
  4.  
  5. public class PythonCaller {
  6.  
  7. public static void main(String[] args) throws IOException {
  8. // set up the command and parameter
  9. String pythonScriptPath = "C:/Python/helloPython.py";
  10. String[] cmd = new String[2];
  11. cmd[0] = "C:/Python27/python.exe";
  12. cmd[1] = pythonScriptPath;
  13.  
  14. // create runtime to execute external command
  15. Runtime rt = Runtime.getRuntime();
  16. Process pr = rt.exec(cmd);
  17.  
  18. // retrieve output from python script
  19. BufferedReader bfr = new BufferedReader(new InputStreamReader(pr.getInputStream()));
  20. String line = "";
  21. while((line = bfr.readLine()) != null) {
  22. // display each output line form python script
  23. System.out.println(line);
  24. }
  25. }
  26. }
  27.  
  28. def Add(x):
  29. x = x + 1
  30. return x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement