1

I am a beginner in Python and I need to call .py script from Java code. I have installed jython but the tutorials I am getting online has material where they are importing Java packages in Python code. But my query is the other way round.

I just need a simple code in Java which is able to run Python scripts(.py).

Any leads will be highly appreciated.

Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
Anisha
  • 167
  • 1
  • 10
  • just search on google "call .py script from java code" and get the answer `Process p = Runtime.getRuntime().exec("python yourapp.py");` – Manuel Lagunas Mar 20 '18 at 08:56

1 Answers1

1

Use jython library or run in CMD:

String command = "python script.py";
Process p = Runtime.getRuntime().exec(command);
Maciej Pulikowski
  • 2,457
  • 3
  • 15
  • 34