On 26.04.2021 20:19, Niranjan Rao wrote:
> On 4/14/21 5:29 AM, Rony G. Flatscher (Apache) wrote:
>> A JVM
>> AFAIK would not honor changes to the environment after it got started
>
> A serious question. Apologies for selective selection from the response.
>
> Are there any operating systems where change in environment is automatically 
> reflected in child
> process? My understanding was, processes always inherit parent environment 
> and have no way of
> knowing what changed.
>
> If you managed to spawn a process with different parent based on your 
> operating system, then you
> might see new values, but most of the spawn/exec calls (regardless of 
> language of implmentation)
> inherit the exact same environment variables. Some calls do allow you to 
> setup the environment
> variables for child process but struggling to figure out where grandparent 
> process informed parent
> about environment change which can be sent to grandchild.

Well, it depends what one does, e.g. spawning a new process is different than 
e.g. changing PATH in
the same process and then relying on the new value for PATH to take effect when 
looking for programs
to run/execute.

An example (Windows, ooRexx):

    test.rex ... an ooRexx script that uses Rexx to find "subdir\hey.rex" and 
uses Windows to find
    "subdir\heyhey.bat", both depend on PATH (which gets changed in the running 
program and takes
    effect as can be seen by the output below); failure is shown with frownies, 
success with smileys :)

    subdir\hey.rex ... an ooRexx script displaying the invocation information 
(operating system, how
    invoked, fully qualified path to this program) and the current dir

    subdir\heyhey.bat ... a batch file displaying some environment variable 
('windir')

Here the output of running "test.rex":

    G:\test\orx\env>test.rex
    1a) testcall():
    :-( | not found!
    1b) testcallbat():
    'heyhey.bat' is not recognized as an internal or external command,
    operable program or batch file.
    :-( | not found! | RC=1

    ... about to add 'G:\test\orx\env\subdir' to PATH ...

    2a) testcall():
    --> hey.rex: parse source s: [WindowsNT SUBROUTINE 
G:\test\orx\env\subdir\hey.rex]
    --> hey.rex: directory()   : [G:\test\orx\env]
    :-) | ok!
    2b) testcallbat():
    *** heyhey.bat: just arrived ***
    *** heyhey.bat: windir=C:\WINDOWS ***
    *** heyhey.bat: about to return ***
    :-) | RC=0

As long as PATH does not contain the "subdir" directory neither "hey.rex" nor 
"heyhey.bat" (this
even causes an error message) are found by Rexx or Windows, cf. 1a) and 1b 
(displays the return code
next to the frownie) above. Once the "subdir" directory gets added in the 
running program (in the
same process) and both programs are found by Rexx and Windows as can be seen by 
the output 2a) and
2b) ("heyhey.bat" is executed in a subprocess with a new environment such that 
its PATH value is
unchanged!).

HTH,

---rony

P.S.: For the record the three files:

subdir\hey.rex:

    #!/usr/bin/env rexx
    parse source s -- get invocation information
    say "--> hey.rex:" "parse source s: ["s"]"           -- show invocation 
information
    say "--> hey.rex:" "directory()   : ["directory()"]" -- show current 
directory

subdir\heyhey.bat:

    @echo off
    echo *** heyhey.bat: just arrived ***
    echo *** heyhey.bat: windir=%windir% ***
    echo *** heyhey.bat: about to return ***

test.rex:

    #!/usr/bin/env rexx
    say "1a) testcall():"   -- call a Rexx program
    say testCall()
    say "1b) testcallbat():"
    res=testcallbat()       -- invoke a command
    say res
    say

    newDir=directory()"\subdir"
    say "... about to add '"newDir"' to PATH ..."
       -- define new value for PATH
    newValue=value('PATH',         ,"environment")";"newDir
    oldValue=value('PATH', newValue, "environment")   -- change PATH value
    say

    say "2a) testcall():"   -- call a Rexx program
    say testCall()
    say "2b) testcallbat():"               -- invoke a command
    res=testcallbat()       -- invoke a command
    say res

    ::routine testcall   -- call another Rexx program
      signal on syntax   -- if syntax exception then jump to label "syntax:"
      call hey.rex       -- call the Rexx program, PATH gets searched
      return ":-) | ok!"    -- everything went fine, return a smiley
    syntax:              -- label
      return ":-( | not found!"   -- return frownie

    ::routine testcallbat         -- call a Windows batch file
      address system "heyhey.bat" -- let Window search and execute the command
      if rc=0 then return ":-) | RC="rc -- if return code is 0 return smiley
      return ":-( | not found! | RC="rc           -- return code indicates 
problem, return frownie




Reply via email to