0

How to export $ORACLE_HOME and $PATH in java program so oracle related commands will work?

If I execute ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 and export PATH=$PATH:$ORACLE_HOME/bin from terminal now if i run Linux command lsnrclt status it gives result.

How can I do this using Java program so that will be in path and i can get result of lsnrctl status command result?

1

1 Answer 1

2

Java's ProcessBuilder provides a environment() method which will return the environment (Map<String, String>) of the process when started. The environment will be initialized with System.getenv(), but the map can be freely changed to suit your needs. So simply Map.put the additional environment variables you need into the Map returned by ProcessBuilder.environment().

Alternatively you can export the environment variables on the shell for your Java program, in that case ProcessBuilder will pass them on to the child processes automatically.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank You pschichtel for your quick response. Can you please give me t code soi can test if any issue I will let you know. The program that will export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 and export PATH=$PATH:$ORACLE_HOME/bin
Big Thank pschichtel
@KailasKakade its iterally just builder.environment().put("ORACLE_HOME", "/u0..............")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.