[SOLVED] Problems with system services / functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shenosuke
Forum Newbie
Posts: 4
Joined: Sun Mar 27, 2005 11:00 pm
Contact:

[SOLVED] Problems with system services / functions

Post by shenosuke »

Wassup guys?
i've been having trouble with this project i'm doing. in short...I"M STUCK!!

I want to display the output of something I 'grep'ed, but the output came out wrong..

here's the code:

Code: Select all

<?
  
	$totalgrep=3;				//amount of processed to be 'grep'ed	
	$grepdata = array();
	$pdetail = array();
	##########HERE IS PROCESS NAME AND ITS COMMAND################

	$grepdataї1]=&quote;iman_aig&quote;;
	
	$grepdataї2]=&quote;iman_emi&quote;;
	
	$grepdataї3]=&quote;iman_smpp&quote;;
		###############################################################

	for($i=1;$i<=$totalgrep;$i++)
	
	{ $pdetailї$i] = popen(&quote;ps -ef|grep &quote;.&quote;'&quote;.$grepdataї$i].&quote;'&quote;.&quote; |grep -v grep&quote;, &quote;r&quote;); 	
	  
}	
	
?>
the next code is in the HTML part of the ProcessDetails.php file

Code: Select all

<?
for ($j=1;$j<=$totalgrep;$j++)
				
	{
	 echo $pdetailї$j]; 
	 echo &quote;<br />&quote;;
								}
		
	 if($pdetail==NULL)
	{
	 echo &quote;No Process Running!&quote;;
	 exit;
	}
	

  
	?>
the output of this codes would come out like this

Code: Select all

Resource id #2
would someone kindly help me with this?
thanx!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it would appear you need to fread() the handle returned by popen() as illustrated by the popen() documentation example:

Code: Select all

<?php
error_reporting(E_ALL);

/* Add redirection so we can get stderr. */
$handle = popen('/path/to/spooge 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
?>
shenosuke
Forum Newbie
Posts: 4
Joined: Sun Mar 27, 2005 11:00 pm
Contact:

Post by shenosuke »

I'm hitting myself real hard right now...WHY HAVEN'T I FOUND THIS FORUM BEFORE?? :D

THANX A LOT feyd! it worked perfectly... :lol:
you really made my day
Post Reply