Batch script for set env. variable startup OC4J and remove env. variable

江枫思渺然 提交于 2019-12-01 14:01:29

The batch file to start the Oracle server just needs the following 2 lines:

set "ORACLE_HOME=C:\Servers\oc4j_extended_101350"
C:\Servers\oc4j_extended_101350\bin\oc4j.exe -start

That's it if oc4j.exe is not a console application and therefore command processor immediately continues processing the batch file after starting oc4j.exe resulting in closing command process.

Otherwise use:

set "ORACLE_HOME=C:\Servers\oc4j_extended_101350"
start "Oracle Server" C:\Servers\oc4j_extended_101350\bin\oc4j.exe -start

Why this works?

Windows creates automatically a copy of the entire environment table of current process for the new process on creating a new process.

For the command process executing the batch file ORACLE_HOME is set in its environment table as specified in the batch file.

On starting the Oracle server this environment table is copied by Windows for the Oracle server including ORACLE_HOME as currently defined. What is defined in Windows registry does not matter and is not taken into account. The Oracle server does not see if there is also ORACLE_HOME set at all and if so with which value for parent processes or other processes running parallel.

A simple example to demonstrate environment table management by Windows.

  1. Open a command prompt window and enter set x=Hello.
  2. Type set x and you see x=Hello.
  3. Execute start resulting in opening a second command prompt window.
  4. Type in this second command prompt window set x and you get displayed also x=Hello.
  5. Switch back to first command prompt window and run set x=Hi.
  6. Type in this first command prompt window set x and you see x=Hi.
  7. Switch again to second command window, type set x and you still see set x=Hello.

    This second command process has got a copy of first command process. So what is changed now in the environment table of first command process is not visible for second command process.

  8. Execute in second command window set x=Bye and verify it with set x.

  9. Switch back to first command window and enter set x.

    It is still output x=Hi because also the parent process does not get back what the child process modifies in its copy of the environment table.

  10. Switch to second command window and enter set path= to delete environment variable PATH from environment table of this process.

  11. Execute once more start to open from second command window a third command window.
  12. Enter set path and you get displayed just

    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    

What happened with system PATH?

System PATH as well as user account related PATH are still set in Windows registry and build together PATH for new processes started from desktop Explorer process. But in the environment tables of second and third command process there is no environment variable PATH anymore. Those two processes must work now without environment variable PATH. Of course for the first command process and all other running processes PATH still exists in their environment tables.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!