Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25751
| From | jasonveldicott@gmail.com |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Calling Java jar class with parameter from Python |
| Date | 2012-07-21 09:11 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <1d773886-2cd0-4f72-b061-1490db6567e8@googlegroups.com> (permalink) |
| References | <CAK4NeTGkCfpMp09hw0-WUjY8t3QUBku=UrMjpXLcmKXwq6HvbA@mail.gmail.com> <mailman.2380.1342873263.4697.python-list@python.org> <roy-B96A3E.09574821072012@news.panix.com> |
On Saturday, July 21, 2012 6:57:48 AM UTC-7, Roy Smith wrote: > In article <mailman.2380.1342873263.4697.python-list@python.org>, > Peter Otten <__peter__@web.de> 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).communicate() > > You might also want to try raw strings. This should be identical to > Peter's version, but easier to read: > > subprocess.Popen([ > r"C:\Program Files (x86)\Java\jdk1.7.0_05\bin\java.exe", > r"-cp", > r"C:\antlr\antlr-3.4-complete.jar", > r"org.antlr.Tool", > r"C:\Users\Jason\Documents\antlr\java grammar\Java.g"], > stdout=subprocess.PIPE).communicate() > > although I would probably refactor it like: > > args = [r"C:\Program Files (x86)\Java\jdk1.7.0_05\bin\java.exe", > r"-cp", > r"C:\antlr\antlr-3.4-complete.jar", > r"org.antlr.Tool", > r"C:\Users\Jason\Documents\antlr\java grammar\Java.g", > ] > proc = subprocess.Popen(args, stdout=subprocess.PIPE) > proc.communicate() The r string notation at least saves having to double type a bunch of backslashes, although the appearance prepended to the string takes a little getting used to. Visually the separate array to handle arguments is perhaps cleaner, having more resemblance to the original command. Thanks for the tips.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Calling Java jar class with parameter from Python Peter Otten <__peter__@web.de> - 2012-07-21 14:20 +0200
Re: Calling Java jar class with parameter from Python Roy Smith <roy@panix.com> - 2012-07-21 09:57 -0400
Re: Calling Java jar class with parameter from Python jasonveldicott@gmail.com - 2012-07-21 09:11 -0700
Re: Calling Java jar class with parameter from Python jasonveldicott@gmail.com - 2012-07-21 09:03 -0700
Re: Calling Java jar class with parameter from Python jasonveldicott@gmail.com - 2012-07-21 09:03 -0700
csiph-web