note 24093 deleted from function.exec by cmb
| From: | cmb@php.net | Date: | Sun, 24 Nov 2019 08:39:36 +0000 |
| Subject: | note 24093 deleted from function.exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213194@lists.php.net to get a copy of this message | ||
Note Submitter: ronperrella at NOSPAM dot hotmail dot com
----
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.)