Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 ./ foo bar [ -f ./ ] && ./ perl prog2 quux

The idea is that prog1 writes valid shell commands to the 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

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

Replies are listed 'Best First'.
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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2021-10-19 03:00 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (76 votes). Check out past polls.