Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Can I do this ???

by grinder (Bishop)
on Jan 22, 2009 at 14:03 UTC ( #738160=note: print w/ replies, xml ) Need Help??


in reply to Can I do this ???

You can do this with a little cooperation between different processes. Consider the following:

#! /bin/sh perl prog1 -x ./env.sh foo bar [ -f ./env.sh ] && ./env.sh perl prog2 quux

The idea is that prog1 writes valid shell commands to the env.sh file, does whatever else it has to do and then exits. Execution flow returns to the outer shell, which then sources the file that it wrote.

The prog2 program then runs, and picks up what ever environment changes were made by env.sh.

This is rather fragile and insecure. If you are brave and insist on this approach you really should consider using IPC (Inter-Process Communication) for a more robust solution. The idea is to create a channel of communication (child writes, parent reads) between the two. See perlipc for more information.

• another intruder with the mooring in the heart of the Perl


Comment on Re: Can I do this ???
Download Code
Re^2: Can I do this ???
by cmv (Chaplain) on Jan 22, 2009 at 18:09 UTC
    grinder++ I agree with you, that parents cooperating with children can cause a change in the parents environment. Hey, that probably holds true in real life as well...

    My contribution here is that I implemented something similar, using unix signals. The parent would trap on an unused signal (I used SIGUSR1) and read-in-and-execute all the commands contained in a pre-defined temporary file.

    When the child wanted to change something in the parents environment, it would write those changes to the pre-defined temporary file, then would poke-the-parent-in-the-side by sending a signal via the unix kill(1) command.

    This worked well for me.

    -Craig

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://738160]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-07-13 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (249 votes), past polls