myuser has asked for the wisdom of the Perl Monks concerning the following question:

I guess it is not possible..

But does somebody knows a way of getting the values of environment from a child process to a parent process ?

Or some workaround to do the same ?
  • Comment on what is the method to get the environment from child process ?

Replies are listed 'Best First'.
Re: what is the method to get the environment from child process ?
by ikegami (Patriarch) on Nov 10, 2010 at 05:57 UTC
    Via a pipe would be an obvious choice. Practically any means of transferring data from the child to the parent could be used to transmit environment variables.
Re: what is the method to get the environment from child process ?
by eyepopslikeamosquito (Archbishop) on Nov 10, 2010 at 09:35 UTC

    This looks like an XY Problem.

    Give us some context of the real problem you are trying to solve and what alternatives you have considered.

Re: what is the method to get the environment from child process ?
by Tux (Canon) on Nov 10, 2010 at 06:52 UTC

    When you are running on an OS that has/supports the proc filesystem, you could read /proc/$pid/environ, but I'm not sure if that is (always) updated if the environment changes for the (sub)process, or that it just reflects the environment at startup. YMMV.


    Enjoy, Have FUN! H.Merijn
Re: what is the method to get the environment from child process ?
by cdarke (Prior) on Nov 10, 2010 at 09:14 UTC
    Only using an IPC mechanism, see perlipc. The environment block in the child is only a copy of that in the parent. Well usually it is a copy, actually the parent can supply a totally different block for the child (on UNIX and Windows).
Re: what is the method to get the environment from child process ?
by BrowserUk (Patriarch) on Nov 10, 2010 at 06:11 UTC
    I guess it is not possible.. But does somebody knows a way of getting the values of environment from a child process to a parent process ?

    Do you perhaps mean "Set environment variables within the parent (shell) process from a child (perl) process?"


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Setting environment in child (perl )process, and getting it in parent ( perl ) process.

      Forking a child perl process from parent perl process.
        Setting environment in child (perl )process, and getting it in parent ( perl ) process. Forking a child perl process from parent perl process.

        You are suggesting using environment vars as an IPC mechanism?

        If so, I don't believe that is possible on any multi-tasking OS.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.