Calling Java jar class with parameter from Python
Jason Veldicott
jasonveldicott at gmail.com
Sat Jul 21 07:35:41 EDT 2012
Hi,
I have read a number of posts on how this can be done, but I have not been
able to replicate success with the particular command I'm wishing to
execute.
I am wanting to execute the following Java command from Python in Windows:
java -cp c:\antlr\antlr-3.4-complete.jar org.antlr.Tool
"C:\Users\Jason\Documents\antlr\java grammar\Java.g"
This command works outside of Python at the command prompt.
So I do the same using Python's os.system:
os.system("C:\\Program Files (x86)\\Java\\jdk1.7.0_05\\bin\\java.exe -cp
c:\\antlr\\antlr-3.4-complete.jar org.antlr.Tool
'C:\\Users\\Jason\\Documents\\antlr\\java grammar\\Java.g'")
The return value is 1, which presumably indicates error.
Another variation using subprocess.call, one of many tried, gives the same
result:
subprocess.call(["C:\\Program Files
(x86)\\Java\\jdk1.7.0_05\\bin\\java.exe", "-cp
c:\\antlr\\antlr-3.4-complete.jar org.antlr.Tool",
"C:\\Users\\Jason\\Documents\\antlr\\java grammar\\Java.g"] )
This variation using subprocess.Popen, gives a result, but it's ('', None).
subprocess.Popen(["C:\\Program Files
(x86)\\Java\\jdk1.7.0_05\\bin\\java.exe", "-cp
c:\\antlr\\antlr-3.4-complete.jar org.antlr.Tool",
"C:\\Users\\Jason\\Documents\\antlr\\java grammar\\Java.g"],
stdout=subprocess.PIPE, shell=True ).communicate()
Obviously, some trick is being missed. Could anyone shed light on what it
may be?
Thanks
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120721/6d0bafe8/attachment.html>
More information about the Python-list
mailing list