|
Posted by Andy Jeffries on 06/25/06 18:57
On Fri, 23 Jun 2006 16:05:46 -0400, David Haynes wrote:
>> php -E 'echo system ("ls ");'
>>
>> <you have to hit ^D after you hit newline>. Anyway, this simple "ls" is
>> also duplicating the last line of output. Is this a bug or feature?
>>
> ls already emits to STDOUT.
>
> So, you have the output from the 'ls' command and then 'echo' echoing the
> last line.
You're *ALMOST* right. ls emits the output to STDOUT, but that is trapped
by PHP when running system. PHP then prints the output of the command
when using the "system" function call and returns the last line (which the
OP then echoes).
But the point is, it's the usage of system that's the problem, not ls.
http://uk.php.net/system
If you really want to run the command and only get the last line, you're
better using exec (which is the same as system, but doesn't print the
output, automatically returns the last line and can optionally return the
full output in an array).
http://uk.php.net/exec
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos
[Back to original message]
|