Set Environment for java based tools thru python script

Derek Martin code at pizzashack.org
Tue Oct 14 18:33:07 EDT 2008


On Mon, Oct 13, 2008 at 05:07:16PM -0700, replysonika at gmail.com wrote:
> I run a Java app with subprocess from Python script. This python
> script is called from another Python Wrapper.
> 
> 
>     python = subprocess.Popen(["toolname.sh", "-args", arg1, arg2],
>                               stdout=subprocess.PIPE,
> stderr=subprocess.PIPE)

This (toolname.sh) looks like a shell script (though technically,
there's no reason it couldn't be a python script).  

Unfortunately, from what you've written here, it's neither clear what
processes start what processes, nor what the intended result is.  You
have said you have 3 programs, but you've only shown the interactions
between two of them.  My suggestion would be to rewrite your request,
explicitly name the processes (even if it is just with letters, A, B,
and C), and show which processes start which other processes, and
probably explain a little about what each one is supposed to do.  That
said, see below.

> I can run it manually from the command line. But fails when I execute
> the wrapper Python script
> 
> How do I source the java environment from the wrapper. It fails with
> the following message.
> 
> ...16605 Segmentation fault      $JAVA_HOME/bin/java $JAVA_OPTIONS -
> classpath $CLASSPATH xxxxxxxxxxxxxxxxxxxxxx "$@"....

Again, it's not clear what you're trying to do, but I'm assuming you
have some script that sets environment variables, and that's what you
mean by "source the java environment..."

If so, you can't.  You either need to source the environment before
running the Python program, or have the python program read a file
that contains the environment and do its own parsing, setting the
environment variables appropriately.  A child process, in general, can
not insert environment variables into the environment of its parent.

If what you're trying to do isn't covered by the above, then I think
you'll need to try to explain it better.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20081014/046c8afa/attachment-0001.sig>


More information about the Python-list mailing list