-
Duplicate: stackoverflow.com/questions/438594/…S.Lott– S.Lott2009年03月31日 20:27:20 +00:00Commented Mar 31, 2009 at 20:27
-
It doesn't quite sound like a duplicate - it sounds more like they want to execute an entire program, not access functions inside a Java class.Andrew Hare– Andrew Hare2009年03月31日 20:29:57 +00:00Commented Mar 31, 2009 at 20:29
-
@Andrew Hare: The accepted answer was "run a Java program from within Python".S.Lott– S.Lott2009年03月31日 21:09:34 +00:00Commented Mar 31, 2009 at 21:09
-
@S.Lott: You are correct! I guess it is a bit of a duplicate.Andrew Hare– Andrew Hare2009年03月31日 23:57:19 +00:00Commented Mar 31, 2009 at 23:57
2 Answers 2
You can execute anything you want from Python with the os.system() function.
os.system(command)
Execute the command (a string) in a subshell. This is implemented by calling the Standard C function system, and has the same limitations. Changes to os.environ, sys.stdin, etc. are not reflected in the environment of the executed command.
For more power and flexibility you will want to look at the subprocess module:
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.
1 Comment
Of course, Jython allows you to use Java classes from within Python. It's an alternate way of looking at it that would allow much tighter integration of the Java code.