Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25751

Re: Calling Java jar class with parameter from Python

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>

Show all headers | View raw


On Saturday, July 21, 2012 6:57:48 AM UTC-7, Roy Smith wrote:
> In article &lt;mailman.2380.1342873263.4697.python-list@python.org&gt;,
>  Peter Otten &lt;__peter__@web.de&gt; wrote:
> 
> &gt; subprocess.Popen([
> &gt;   &quot;C:\\Program Files (x86)\\Java\\jdk1.7.0_05\\bin\\java.exe&quot;,
> &gt;   &quot;-cp&quot;,
> &gt;   &quot;C:\\antlr\\antlr-3.4-complete.jar&quot;,
> &gt;   &quot;org.antlr.Tool&quot;,
> &gt;   &quot;C:\\Users\\Jason\\Documents\\antlr\\java grammar\\Java.g&quot;],
> &gt;    stdout=subprocess.PIPE).communicate()
> 
> You might also want to try raw strings.  This should be identical to 
> Peter&#39;s version, but easier to read:
> 
> subprocess.Popen([
>   r&quot;C:\Program Files (x86)\Java\jdk1.7.0_05\bin\java.exe&quot;,
>   r&quot;-cp&quot;,
>   r&quot;C:\antlr\antlr-3.4-complete.jar&quot;,
>   r&quot;org.antlr.Tool&quot;,
>   r&quot;C:\Users\Jason\Documents\antlr\java grammar\Java.g&quot;],
>    stdout=subprocess.PIPE).communicate()
> 
> although I would probably refactor it like:
> 
> args = [r&quot;C:\Program Files (x86)\Java\jdk1.7.0_05\bin\java.exe&quot;,
>         r&quot;-cp&quot;,
>         r&quot;C:\antlr\antlr-3.4-complete.jar&quot;,
>         r&quot;org.antlr.Tool&quot;,
>         r&quot;C:\Users\Jason\Documents\antlr\java grammar\Java.g&quot;,
>        ]
> 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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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