how to edit shell_exec output

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
starkom
Forum Newbie
Posts: 2
Joined: Wed Jun 29, 2005 9:30 am

how to edit shell_exec output

Post 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);
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
starkom
Forum Newbie
Posts: 2
Joined: Wed Jun 29, 2005 9:30 am

break up the output - how to do this

Post by starkom »

can u let me know how break up the output

thanks
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Look up explode(). If you're running on Linux, the newline character is

Code: Select all

\r\n
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply