Jump to content


Photo

Is it possible to parse the output of the 'system' command?


  • Please log in to reply
5 replies to this topic

#1 chris.zeman

chris.zeman
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 11 August 2006 - 05:25 AM

I am using the system command, as shown below, to display system information on my web page.
<?php 
     system("free -m"); 
?>

I'd like to parse the output and generate my own tables, but haven't been able to find any information on how to do it. Is it possible to do this in PHP?

Thanks,
Chris

#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 11 August 2006 - 05:46 AM

could probably use output buffering.  look up ob_start() and ob_end_get(); or something similar.  essentially captures output and lets you do with it as you please once you cease capturing it.

#3 longree

longree
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 11 August 2006 - 11:10 AM

Simple Solution:

<?php 
     $cmd =   system("free -m"); 
     echo"$cmd";
?>

Edit[Sorry, didn't see you wanted to put it into tables... hmm... i'll come back on this one...]

#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 11 August 2006 - 04:18 PM

it's not just that he wants it put into tables, but the system() function only returns the LAST LINE of the command's output.

#5 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 04:28 PM

what if you used 'free -m > system.txt' to pipe the command thru to a temporary text file?

Then you can read the file back in and will contain the whole output of the command..

not sure if this works but worth a shot?

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 11 August 2006 - 04:33 PM

exec($command, $output, $return_value); What does the output look like?
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users