Calling Java jar class with parameter from Python

Peter Otten __peter__ at
Sat Jul 21 14:20:48 CEST 2012

Jason Veldicott wrote:

> 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?

File names with spaces can be tricky. Try thoroughly separating the 
individual arguments and let subprocess do the necessary escaping. 
I think it should be

  "C:\\Program Files (x86)\\Java\\jdk1.7.0_05\\bin\\java.exe",
  "C:\\Users\\Jason\\Documents\\antlr\\java grammar\\Java.g"],

More information about the Python-list mailing list