You are here: Re: system() returns the last line of output twice « PHP Programming Language « IT news, forums, messages
Re: system() returns the last line of output twice

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация