Jump to content

Archived

This topic is now archived and is closed to further replies.

chris.zeman

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

Recommended Posts

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Simple Solution:

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[tt]exec($command, $output, $return_value);[/tt] What does the output look like?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.