Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Setting environment variables from java

Thread view: 
Karim - 01 Jun 2007 02:44 GMT
Hi,

Under linux, I have java code that runs a c executable using
Runtime.getRuntime().exec()

Before running that I have to set the LD_LIBRARY_PATH system
variable..

I tried Runtime.getRuntime().exec("setenv ....")
Runtime.getRuntime().exec("export ... ")

and I also tried System.setProperty();

and non of the above seem to do the trick..

any hints?

Thanks
Martin Gregorie - 01 Jun 2007 12:21 GMT
> Hi,
>
[quoted text clipped - 10 lines]
>
> and non of the above seem to do the trick..

Runtime.getRuntime().exec will start a separate shell each tine its
called, so nothing do in one call can affect the environment for a
subsequent call. I think your best choices are:

- run a script that sets the environment before running the program
- change .profile in the user you're running under to set
  LD_LIBRARY_PATH
- recompile the program with static linking

...listed with best choice first.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Gordon Beaton - 01 Jun 2007 13:43 GMT
> Runtime.getRuntime().exec will start a separate shell each tine its
> called, so nothing do in one call can affect the environment for a
> subsequent call.

However at least one version of Runtime.exec() lets you specify the
environment for the child process being invoked. Combine that with
System.getEnv() and you can make changes to the default enviromnent
before passing it to Runtime.exec().

Or use ProcessBuilder.environment().

/gordon

--
Nigel Wade - 01 Jun 2007 17:24 GMT
>> Hi,
>>
[quoted text clipped - 21 lines]
>
> ...listed with best choice first.

or do what Robert suggested when this post was sent yesterday...

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.