ENV variables in perl scripts called from perl.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sandman

    ENV variables in perl scripts called from perl.

    The subject says it all. I am doing a:

    I have a perl script in which I am using a ReadParse routine that parses the
    $ENV{'QUERY_STR ING'} or $ENV{'CONTENT_L ENGTH'} which are two variables passed
    to the script under usual SSI (.shtml) containing form data submitted to the
    page from which the script is executed from.

    Well, since switching to PHP, I have moved most of my perl scripts to php
    equivalents, but there are a few perl scripts that are just too big for me to
    try to convert them, and I am unsure if what they do could even be accomplished
    by PHP. So I am going to continue to use them. The problem, though, is that
    when I use...

    print shell_exec("scr ipt.pl");

    ....to execute the scripts, these environment variables aren't passed and the
    script cannot perform it's task. Is there a way to circumvent this, and pass
    these through?

    I have found that doing this is my perlscript:

    foreach (keys %ENV){
    print "$_ -> $ENV{$_}<br>";
    }

    Outputs alot of variables, where one reads:

    HTTP_SERVER_VAR S -> Array

    I suspect that this $ENV variable might be an array of all my wanted ariables,
    allthough I must confess that I do not know how to list them or use them, if
    so. I tried...

    print $ENV{'HTTP_SERV ER_VARS'}{'QUER Y_STRING'};

    ....but that yielded nothing. So I am at loss, and I am hoping someone out there
    has a solution for my predicament.

    Thank you in advance!

    --
    Sandman[.net]
  • Terence

    #2
    Re: ENV variables in perl scripts called from perl.

    You perl script will NEVER inherit the environment of the calling PHP
    script. You will have to serialise the data from PHP to a place where
    perl can find it.

    one option is to store wddx string which you can then "pipe" to the perl
    script which will then need a routine to deseriliase it from wddx.

    you may have to use popen() or proc_open()

    also check out the wddx functions. I only suggest that because it is
    cross-language and simple. you could also use XML-RPC packets but that
    would be more involed.

    see if there is a perl function which can "deserializ e()" a PHP
    "serialize( )". If so (unlikely), this would be most efficient (easiest)

    use piping. you don't want to mess around with writing temporary files
    and race conditions etc...

    Sandman wrote:[color=blue]
    > The subject says it all. I am doing a:
    >
    > I have a perl script in which I am using a ReadParse routine that parses the
    > $ENV{'QUERY_STR ING'} or $ENV{'CONTENT_L ENGTH'} which are two variables passed
    > to the script under usual SSI (.shtml) containing form data submitted to the
    > page from which the script is executed from.
    >
    > Well, since switching to PHP, I have moved most of my perl scripts to php
    > equivalents, but there are a few perl scripts that are just too big for me to
    > try to convert them, and I am unsure if what they do could even be accomplished
    > by PHP. So I am going to continue to use them. The problem, though, is that
    > when I use...
    >
    > print shell_exec("scr ipt.pl");
    >
    > ...to execute the scripts, these environment variables aren't passed and the
    > script cannot perform it's task. Is there a way to circumvent this, and pass
    > these through?
    >
    > I have found that doing this is my perlscript:
    >
    > foreach (keys %ENV){
    > print "$_ -> $ENV{$_}<br>";
    > }
    >
    > Outputs alot of variables, where one reads:
    >
    > HTTP_SERVER_VAR S -> Array
    >
    > I suspect that this $ENV variable might be an array of all my wanted ariables,
    > allthough I must confess that I do not know how to list them or use them, if
    > so. I tried...
    >
    > print $ENV{'HTTP_SERV ER_VARS'}{'QUER Y_STRING'};
    >
    > ...but that yielded nothing. So I am at loss, and I am hoping someone out there
    > has a solution for my predicament.
    >
    > Thank you in advance!
    >[/color]

    Comment

    • Sandman

      #3
      Re: ENV variables in perl scripts called from perl.

      In article <3f1f8b1a$1@cic ada>, Terence <tk.lists@fastm ail.fm> wrote:
      [color=blue]
      > You perl script will NEVER inherit the environment of the calling PHP
      > script. You will have to serialise the data from PHP to a place where
      > perl can find it.[/color]

      Are you for real? Why is this true?

      Pardon me for saying this - but that would be a mayor PITA...

      --
      Sandman[.net]

      Comment

      Working...