Jump to content

Recommended Posts

What I am trying to solve: Call a PERL Script which requires a certain environment variable to be set. $_ENV['name'] does not work, nor does putenv('name=val'), as the PERL Script still gets a null as the environment variable when it calls $ENV{'name'}

 

Details: I would like to set-up a bunch of environment variables that my server has access to, there is a script which I can call which sets-up these environments. From what I can tell the apache environment grabs it's variables from the user which calls it when it starts(In this case root). There's a script I can call that will set-up all of my Environment variables, and I'm wondering if I can just call that from inside my webserver and it will set everything up so that the PERL script can see the variables?

 

Alternatively, is there any other way I can import all of these environment variables so that the PERL script can see them?

 

Right now I've got a hacked together method using a file input which I'd prefer didn't stay, since it's another job they have to remember to run once I'm gone[And I can't seem to get PERL to understand it has the variable name it's looking for...]

hum...i'm not too familiar with HP, but most *nix systems, there is a file called .profile in the users home dir. in that file you can specify user specific environmental variables. that file should get run when it's executing scripts *untested*

 

the lines in the file should look something like this (this is how i do it on linux/aix):

export MYVAR=abcdef
export MYOTHERVAR=/path/to/something

I've got a script which sets-up the variables, setting up the Environment isn't a problem. The problem is this:

 

The server gets it's variables from the root environment when it's called from what I can gather. I can't set-up the environment from the root, since that involves running that script from root, which I don't want to do[And because it's a pain an requires some odd customization which is a hassle]

 

Now I've managed to get some environment variables into it, but a new problem is it's not being passed out from the web server when it tries to call a script(In this case a PERL Script).

 

Essentially a variable called VAR1 needs to be 1 in order for this script to work, I try to set it up from the php page, and it doesn't work. I've tried $_ENV['VAR1']=1, putenv("VAR1=1"), apache_setenv('VAR1',1),$_SERVER['VAR1']=1 and none of these have the desired effect. If I do an exec(echo "$VAR1"), it returns a null value like it hasn't been set, regardless of which commands I place before it.[i can't just add this into the .profile, since VAR1 has to change slightly depending on where it's being called from]

 

Also: Where would the .profile be for the apache server? Right now it's running as my own user which has a lot of these variables set, but it doesn't grab them(I just ran a test, I modified a variable from my user side, and my page didn't grab the updated value it's still using it's own)

 

Edit: Also it seems I mislabeled my title...It should be form the server, not for the server...

Interesting, cus I do that all the time on my Debian/Apache/PHP setup. I set an environment variable then execute another PHP script. My code looks like this:
[code]<?php
  putenv("SOMEDATA=foobar");
  exec("php -f test.php");

?>[/code]

 

and test.php can read the environmental variable fine

 

instead of environmental variables can you pass them as command line arguments?

When I change the variables I can see them internally if I print them from inside the server, I just can't see them from outside the server(i.e. calling an echo on the variable name returns the old value still)

 

<?php
   putenv("var1=1");
   echo getenv("var1"); //This will return 1
   echo exec("echo var1"); //This will return ""
?>

 

Correction, putenv/getenv seem to work when I call the echo. Hrm...Still doesn't get passed to my PERL Script though.

 

It might be possible to modify the script but that'd be a last resort option, since:

 

A) This is working in someone else's set-up, although I can't contact them at the moment to see what they did. And they're using a vastly different set-up then me[Older PHP version I think specifically, and a Custom Session using a DB so they might be doing something there I'm unaware of. And they're using DB_SQL classes while I'm tweaking it to use OCI8]

B) This script isn't designed specifically for this application, it's used elsewhere, and I'm just using it to help with another view of the data I'm displaying.(I have no idea what the page is even supposed to do so I can't even hope to begin to re-write it to work without it)

passthru and exec do the same thing, they just handle the response differently. passthru sends the output of the command directly to the output of the command running it. exec returns the last line i think and stores the output in an argument passed by reference. check php.net for more details on that

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.