Reputation: 21
I am translating some java code into Jython and there is a point where I need to call java.lang.Runtime. The code in Java reads:
Runtime.getRuntime().exec(cmd);
I need this to translate to Jython, but it confuses "exec" with Python's built in exec function. I searched and found suggestions to use something like -
from java.lang.Runtime import exec as javaExec
or
import java.lang.Runtime.exec as javaExec
but the first still confuses the two versions of exec, and the second doesn't allow for the call to getRuntime().
Is there a way to write this line in Jython by either using Python's functions or Java's functions without the naming conflict?
Upvotes: 2
Views: 744
Reputation: 76965
javaexec = getattr(Runtime.getRuntime(), "exec")
That should work. Even better:
import subprocess
subprocess.Popen(cmd)
Upvotes: 3