note 36766 deleted from function.exec by cmb
| From: | cmb@php.net | Date: | Sun, 24 Nov 2019 08:39:58 +0000 |
| Subject: | note 36766 deleted from function.exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213195@lists.php.net to get a copy of this message | ||
Note Submitter: nehle at dragonball-se dot com
----
Remember that some shell commands in *NIX needs you to set a TERM enviroment. For example:
<?php
exec('top n 1 b i', $top, $error );
echo nl2br(implode("\n",$top));
if ($error){
exec('/usr/bin/top n 1 b 2>&1', $error );
echo "Error: ";
exit($error[0]);
}
?>
This will echo "Error: TERM enviroment variable not set. " To fix it, add TERM=xterm (Or
some other terminal) to the exec-statement, like this
<?php
exec('TERM=xterm /usr/bin/top n 1 b i', $top, $error );
echo nl2br(implode("\n",$top));
if ($error){
exec('TERM=xterm /usr/bin/top n 1 b 2>&1', $error );
echo "Error: ";
exit($error[0]);
}
?>