Calling Java jar class with parameter from Python

jasonveldicott at gmail.com jasonveldicott at gmail.com
Sat Jul 21 12:03:57 EDT 2012


On Saturday, July 21, 2012 5:20:48 AM UTC-7, Peter Otten wrote:
> 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
> 
> 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).communicate()

That did the trick, thanks.  

I had the impression from another post that the breaking up of command strings into subprocess arguments could be done arbitrarily as needed to deal with nested inverted commas.  Obviously as you've shown, this is not the case, at least for Popen.



More information about the Python-list mailing list