Skip to content Skip to sidebar Skip to footer

Running Java Main Class Using Subprocess.Popen In Python

I want to execute java main class main.java by python using subprocess.Popen(). main.java takes 3 args. I wonder how to do it? For example I have a HelloWorld.java class: public cl

Solution 1:

You may run your java file with extension .class the following way:

java your.path.Main arg1 arg2

where,

  • java - command, which runs the Java interpreter
  • your.path.Main - full name of your class (without .class)
  • arg1 arg2 - the arguments (written by spaces or between ")

Further, when you formatted this line, it transmits in subprocess.Popen() as argument.

subprocess.Popen('java your.path.Main arg1 arg2')

I'm not Python programmer, because I advice you to read documentation about this method.


Post a Comment for "Running Java Main Class Using Subprocess.Popen In Python"