Re: whoami explanation
| From: | Daniel Brown | Date: | Tue, 03 Mar 2009 15:54:34 +0000 |
| Subject: | Re: whoami explanation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-289131@lists.php.net to get a copy of this message | ||
On Tue, Mar 3, 2009 at 10:42, PJ <af.gourmet@videotron.ca> wrote:
> This really needs some explanation
> I found this on the web:
> <?php echo
whoami; ?>
> with it there was the comment "the direction of those single-quotes matters"
> (WHY ?)
Those are called "backtick operators." Like in BASh and most
other *NIX shells, that instructs the parser to evaluate, execute, and
return the result of the command within the ticks.
> But this (_*FROM THE PHP MANUAL***_ * - exec()* executes the given
> /command/ ) does not,
> COPIED AND PASTED:
> |<?php
> // outputs the username that owns the running php/httpd process
> // (on a system with the "whoami" executable in the path)
> echo exec('whoami');
> ?> |
> What is going on here?
What you want to do with exec() is run it properly (RTFM for real ;-P).
<?php
exec('whoami',$ret,$err);
echo $ret[0]."\n";
?>
The second parameter passed to exec() is the return array from
STDOUT, the third is the error response on channel 2 (STDERR).
> And I often find such discrepancies in examples - and some wonder why I
> seem to be so stupid... and don't know the fundamentals... :-\
I highly doubt that you're stupid.... you just need to pay closer
attention to what the manual is actually saying. Check the user notes
as well, and then devise your own pattern from the collective examples
--- it'll jump-start your learning.
--
</Daniel P. Brown>
daniel.brown@parasane.net || danbrown@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000