note 24093 modified in function.exec by danbrown
| From: | danbrown@php.net | Date: | Sun, 04 Jan 2009 16:37:13 +0000 |
| Subject: | note 24093 modified in function.exec by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148819@lists.php.net to get a copy of this message | ||
I ran into the problem of not being able to set environment variables for my kornshell scripts. In
other words, I could not use putenv() (at least to my understanding).
The solution I used was to write a script on the fly, then execute that script using exec().
<?php
$prgfile = tempnam("/tmp", "SH");
chmod($prgfile, 0755);
$fp = fopen($prgfile, "w");
fwrite($fp, "#!/bin/ksh\n");
fwrite($fp, "export MYENV=MYVALUE\n");
fwrite($fp, "ls -l\n"); // or whatever you wanna run
fclose($fp);
exec($prgfile, $output, $rc);
?>
then delete the temp file (I keep it around for debugging.)
--was--
I ran into the problem of not being able to set environment variables for my kornshell scripts. In
other words, I could not use putenv() (at least to my understanding).
The solution I used was to write a script on the fly, then execute that script using exec().
$prgfile = tempnam("/tmp", "SH");
chmod($prgfile, 0755);
$fp = fopen($prgfile, "w");
fwrite($fp, "#!/bin/ksh\n");
fwrite($fp, "export MYENV=MYVALUE\n");
fwrite($fp, "ls -l\n"); // or whatever you wanna run
fclose($fp);
exec($prgfile, $output, $rc);
then delete the temp file (I keep it around for debugging.)
http://php.net/manual/en/function.exec.php