Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: passing env{} variable to child fails on linux,works on windows

by flexvault (Parson)
on Jan 12, 2013 at 16:48 UTC ( #1013052=note: print w/ replies, xml ) Need Help??


in reply to passing env{} variable to child fails on linux,works on windows

Hello sdetweil,

Since you are testing for MS and treating the problem different for *nix and MS, you may not know about '/dev/shm' which most modern *nix have. If you do a 'df' you'll see if it's there. What this does is allow you to share information between different processes in *nix. It treats memory as a separate filesystem for you to 'open/read/write/close' in memory files without going to disk.

In my testing, I've found it to be 2 or more times faster than using disk, and it's 'cleaned-up' on re-boot.

I don't think the method you're using in *nix will work, since there is no relationship between the process created with 'open' and your process. Why it works in MS, someone else will have to explain. If you use 'fork', all variables are copied to the new process, so you can say:

our $test_switch = 1; ## I recommend using 'our' over 'my' i +n this case ## It signals that it's something to b +e shared
and it will be available in the new 'fork'ed process.

Good Luck!

"Well done is better than well said." - Benjamin Franklin


Comment on Re: passing env{} variable to child fails on linux,works on windows
Download Code
Re^2: passing env{} variable to child fails on linux,works on windows
by sdetweil (Sexton) on Jan 12, 2013 at 19:03 UTC
    >since there is no relationship between the process created with 'open' and your process

    well, there it is then.. its not a 'child' its a peer..

    never a dull moment..

    thanks..

    we have to think on the best way to do this..

      sdetweil,

      How about:

      my @results = qx/script.plx -$envparm/;

      You get the results of the script in '@results' and you pass your script the required parameter that it needs.

      Maybe?

      Regards...Ed

      "Well done is better than well said." - Benjamin Franklin

      well, there it is then.. its not a 'child' its a peer..
      Flexvault is mistaken. It's a child, and it does inherit environment variables. Here are a couple of linux scripts that demonstrate this. First, /tmp/myenv just prints any environment variables that have 'MY' in the name:
      #!/usr/bin/perl print "$_=>$ENV{$_}\n" for grep /MY/, sort keys %ENV;
      Then the main script, which 'opens' myenv:
      #!/usr/bin/perl $ENV{MYA} = 'a'; $ENV{MYB} = 'b'; $ENV{C} = 'c'; open(CMD, "/tmp/myenv 2>&1 |") or die "open: $!\n"; while (<CMD>) { chomp; print "got: <$_>\n"; }
      Running this gives:
      got: <MYA=>a> got: <MYB=>b>

      Dave.

        thank you.

        using your example I tested on my platform, and it worked.

        but my app didn't..

        the difference was that I called $ENV{} from the thread code (&routine below), vs the main app code..

        threads->create(&routine);


        moving the $ENV{} to the main code allows it to work.

        $ENV{'SKIP_SYSTEM'}='1'; threads->create(&routine);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-10-20 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (93 votes), past polls