473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

system() returns the last line of output twice

Hi,

I am running php v 5.0.0 on a redhat box. I have a php script in a
file called p_script_1. I have another small script in file
p_script_2. p_script_1 calles p_script_2 through a system() call. THe
last line of the output from p_script_2 is duplicated. As a test I ran

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?
Oh, just got access to a brand new, up to date RedHat box running php
5.1.4 and it is happening there too.

Jun 23 '06 #1
3 2820
seven.reeds wrote:
Hi,

I am running php v 5.0.0 on a redhat box. I have a php script in a
file called p_script_1. I have another small script in file
p_script_2. p_script_1 calles p_script_2 through a system() call. THe
last line of the output from p_script_2 is duplicated. As a test I ran

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?
Oh, just got access to a brand new, up to date RedHat box running php
5.1.4 and it is happening there too.

ls already emits to STDOUT.

So, you have the output from the 'ls' command and then 'echo' echoing
the last line.

try php -E 'system("ls");' to see the difference.

To see what is really happening, try this:
php -E 'echo -->.system("ls");'

-david-

Jun 23 '06 #2
Doh! thanks David. ... why didn't i try that? sigh

Jun 23 '06 #3
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

Jun 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
1
by: Randy Jackson | last post by:
I'm attempting to debug some code that uses the System function. When the function is called, it returns Error 1. Does anyone know what that error might be, or where I can find a list of error...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
8
by: Oski | last post by:
Hello, our server got hacked through a security hole in an open source php chat script. (nothing new so far, ok!) This chat script allowed the user to create a new php script on our server,...
14
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
7
by: ramana | last post by:
I'm wondering if someone could point me to the flaw in the following code that uses the while(!FP.eof()) condition to read the input data. This condition is reading the last data point of the file...
4
by: sebastien.willemijns | last post by:
hello, i use a small PHP script to grab DNS infos at http://80.247.230.136/bug/php/ (php and txt available) the trouble is the last line of every output given by "system" function is always...
30
by: Yorian | last post by:
Hey, Although I've been using classes and object for quite a while now I've never actually programmed proper OO code yet. It ofcourse depends on what you call proper OO code. I have been...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.