Page 1 of 1

how to edit shell_exec output

Posted: Wed Jun 29, 2005 9:57 am
by starkom
hi

thanks for looking info this request, when i run this script
<?php $output = shell_exec('/usr/local/xpgk/bin/mp_shell.sh sh st 2>&1');
echo "<pre>$output</pre>"; ?>

i get this result

Mera VoIP Transit Softswitch ( 300 Advanced )
Release 2.1.8(Jun 23 2004 19:05:51)
---------------------- Common statistics ----------------------
Host : 205.150.74.182
Start time : 27/06/2005 17:53:58
Up time : 1 days 16 hours 45 minutes
Stat start time : 27/06/2005 17:53:58
Stat duration : 1 days 16 hours 45 minutes
Max load : 2 calls
Calls duration : 0 minute(s)
Active calls : 0
Active AVG 5 min : 0
Received calls : 33
Normal calls : 24
Failed calls : 9
Rejected calls : 0
Received Kb : 1750
Written Kb : 1739


wanted to know edit this and catch in for later use in tables>> here is added code i used but did not work

while(list($number,$value) = each($output)){
list($starttime,$maxload,$activecalls,$rejeted,)=split(', ',$value);

Posted: Wed Jun 29, 2005 10:09 am
by pickle
The result will likely be returned as a single string. If it gets returned like formatted just like you showed, then there are newline characters in that result that you can use to break up the output. From there, you can run any number of regular expression or string manipulation functions to find the info you want.

break up the output - how to do this

Posted: Wed Jun 29, 2005 11:07 am
by starkom
can u let me know how break up the output

thanks

Posted: Wed Jun 29, 2005 11:31 am
by pickle
Look up explode(). If you're running on Linux, the newline character is

Code: Select all

\r\n

Posted: Wed Jun 29, 2005 5:14 pm
by Chris Corbyn
pickle wrote:Look up explode(). If you're running on Linux, the newline character is

Code: Select all

\r\n
Whoops... that's windows ;)

Just "\n" for *nix systems... the \r return character makes funny ^M's at the ends of the lines i think, like you transferred ascii in binary mode and you need dos2unix to mend it :P

Remember, these escaped characters only work in double quoted strings too ;)

Posted: Wed Jun 29, 2005 5:20 pm
by pickle
*Ahem*.... Congratulations - you passed my test! Ya - I was just testing you :oops:

I had a nagging feeling in the back of my head that I was giving the wrong endline character. Maybe I'll listen to those voices in my head a little more.