Results 1 to 4 of 4
  1. #1
    java_kick is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default set environment variable in unix using java program

    Hi,

    I opened eclipse from a shell in Solaris. Now i am able to read the system environment variables using System.getenv() method. But now, i would like to set an environment variable back to shell using java itself.

    Could any body help in this regard.

    Thanks in Advance...

    Raju

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    You can't. It wouldn't do any good, anyway, as it would only affect the shell in which the JVM is running.

    If it is that, you want to be able to execute a system command, and ensure that it has the proper environment, then check out the API docs for ProcessBuilder.

  3. #3
    java_kick is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default

    If it effects the current shell where the JVM is running, it is fine for me.

    Can you tell me how can i set that the env variable back to the shell where eclipse is launched?

    Raju

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by java_kick View Post
    If it effects the current shell where the JVM is running, it is fine for me.

    Can you tell me how can i set that the env variable back to the shell where eclipse is launched?

    Raju
    That is not the shell in which the current JVM is running. When Eclipse launches a project/application, it starts a new JVM, which, of course, gets it's own shell. And like I said, you can't do it, and even if you could it would only affect the current running JVM.

    You might try using Runtime.exec/ProcessBuilder but it probably won't work, and success rates are liable to vary from platform to platform.

Similar Threads

  1. can java program display icon on unix?
    By java2008 in forum Advanced Java
    Replies: 1
    Last Post: 10-06-2008, 08:33 AM
  2. how to run java app on windows in a cron like on unix
    By rockie12 in forum Advanced Java
    Replies: 7
    Last Post: 05-23-2008, 02:39 PM
  3. using java to login to unix
    By dowell in forum Advanced Java
    Replies: 4
    Last Post: 05-23-2008, 08:26 AM
  4. Passing Environment Variable in Eclipse Europa
    By ajaymenon.k in forum Eclipse
    Replies: 0
    Last Post: 11-19-2007, 11:08 AM
  5. Running java program with arguments in Unix"
    By gvi in forum Advanced Java
    Replies: 2
    Last Post: 11-08-2007, 08:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •