note 24093 added to function.exec
| From: | ronperrella at NOSPAM dot hotmail dot com | Date: | Tue, 06 Aug 2002 15:04:45 +0000 |
| Subject: | note 24093 added to function.exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-34400@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().
$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://www.php.net/manual/en/function.exec.php
http://master.php.net/manage/user-notes.php?action=edit+24093
http://master.php.net/manage/user-notes.php?action=delete+24093
http://master.php.net/manage/user-notes.php?action=reject+24093