trq Posted May 6, 2007 Share Posted May 6, 2007 I'm trying to create a nice clean $_ENV array as part of a Linux package management system I'm building with php, but Im having a hard time finding out when exactly it is that php's $_ENV array is built. I have this bash file (env.sh). #!/bin/bash FOO="this is foo" ; export FOO And this php file (envtest.php) #!/usr/bin/bash <?php exec("source env.sh"); print_r($_ENV); ?> Executing this... $ ./envtest.php | grep FOO I get nothing. Executing... $ FOO="this is foo" ; export FOO ; ./envtest.php I still get nothing, but.... $ FOO="this is foo" ; export FOO ; php -r 'print_r($_ENV);' | grep FOO returns... [FOO] => this is foo Anyone tried this before? Whats gives? Quote Link to comment https://forums.phpfreaks.com/topic/50296-solved-sourcing-bash-variables-from-php/ Share on other sites More sharing options...
Trium918 Posted May 6, 2007 Share Posted May 6, 2007 LOL, thorpe. No No.... Your are the greatone!!! You shouldn't need any help. LOL Quote Link to comment https://forums.phpfreaks.com/topic/50296-solved-sourcing-bash-variables-from-php/#findComment-246897 Share on other sites More sharing options...
trq Posted May 7, 2007 Author Share Posted May 7, 2007 Yeah...its been a while since Ive posed a question. Anyway, Ive figured out the problem. It appears exec spawns another process, hence FOO is being set, but not within the same environment as my script. It would also appear that there is no work around for this. Looks like I will be writing this application in Python instead. Not real impressed, but you get that on big jobs I suppose. I was so hoping PHP might be up to the task. Quote Link to comment https://forums.phpfreaks.com/topic/50296-solved-sourcing-bash-variables-from-php/#findComment-246910 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.