1 Reply Latest reply: Aug 14, 2013 5:46 PM by jomy.george RSS

    using environment variable with runtime exec

    jomy.george

      Im trying to execute a program using runtime.exec() that exists in a specific directory set within an environment variable on unix platform. I can see that runtime.exec can see the variable when executing the "set" command, however when passing the command refering to the variable it does not work.

       

      The following example illustrates my problem,

      runtime.exec("set); Outputs the Environment Variable

      runtime.exec("cd %ORACLE_HOME"); Does Not Work

       

      Please Advise

        • 1. Re: using environment variable with runtime exec
          rp0428

          jomy.george wrote:

           

          Im trying to execute a program using runtime.exec() that exists in a specific directory set within an environment variable on unix platform. I can see that runtime.exec can see the variable when executing the "set" command, however when passing the command refering to the variable it does not work.

           

          The following example illustrates my problem,

          runtime.exec("set); Outputs the Environment Variable

          runtime.exec("cd %ORACLE_HOME"); Does Not Work

           

          Please Advise

          You need to post the code that PRODUCES the problem; not just 'illustrate' it. There isn't enough in what you posted to know what is happening.

           

          You also haven't told us what PROBLEM you are trying to solve. Clearly it isn't useful to set an environment variable and then execute a directory change when all of that disppears right afterward. Your Java code will never see any of that or be able to use that new environment variable.

           

          So what is it you actually want to execute on the host?

           

          Have you considered using ProcessBuilder instead?