Charm_quark
Charm_quark

Reputation: 386

php system function gives unusual output

my php code

$last_line = system('service airtime-media-monitor status');
echo $last_line;

my browser displays

    AIRTIME_STATUS_URL             = [1;32mhttp://localhost:80/api/status/format/json/api_key/%%api_key%%[0m
AIRTIME_SERVER_RESPONDING      = [1;32mOK[0m
KERNEL_VERSION                 = [1;32m2.6.32-21-generic[0m
MACHINE_ARCHITECTURE           = [1;32mi686[0m
TOTAL_MEMORY_MBYTES            = [1;32m2051244[0m
TOTAL_SWAP_MBYTES              = [1;32mUNKNOWN[0m
AIRTIME_VERSION                = [1;32m2.3.1[0m
OS                             = [1;32mUbuntu 10.04 LTS i686[0m
CPU                            = [1;32mIntel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz[0m
WEB_SERVER                     = [1;32mApache/2.2.14 (Ubuntu)[0m
PLAYOUT_ENGINE_PROCESS_ID      = [1;32m1195[0m
PLAYOUT_ENGINE_RUNNING_SECONDS = [1;32m121517[0m
PLAYOUT_ENGINE_MEM_PERC        = [1;32m0.5%[0m
PLAYOUT_ENGINE_CPU_PERC        = [1;32m0.4%[0m
LIQUIDSOAP_PROCESS_ID          = [1;32m4362[0m
LIQUIDSOAP_RUNNING_SECONDS     = [1;32m4564[0m
LIQUIDSOAP_MEM_PERC            = [1;32m0.7%[0m
LIQUIDSOAP_CPU_PERC            = [1;32m11.4%[0m
MEDIA_MONITOR_PROCESS_ID       = [1;32m1489[0m
MEDIA_MONITOR_RUNNING_SECONDS  = [1;32m121509[0m
MEDIA_MONITOR_MEM_PERC         = [1;32m0.5%[0m
MEDIA_MONITOR_CPU_PERC         = [1;32m0.0%[0m
-- Your installation of Airtime looks OK!
-- Your installation of Airtime looks OK!null

and this is how the command actually displays this

AIRTIME_STATUS_URL             = http://localhost:80/api/status/format/json/api_key/%%api_key%%                                        
AIRTIME_SERVER_RESPONDING      = OK
KERNEL_VERSION                 = 2.6.32-21-generic
MACHINE_ARCHITECTURE           = i686
TOTAL_MEMORY_MBYTES            = 2051244
TOTAL_SWAP_MBYTES              = UNKNOWN
AIRTIME_VERSION                = 2.3.1
OS                             = Ubuntu 10.04 LTS i686
CPU                            = Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
WEB_SERVER                     = Apache/2.2.14 (Ubuntu)
PLAYOUT_ENGINE_PROCESS_ID      = 1195
PLAYOUT_ENGINE_RUNNING_SECONDS = 121187
PLAYOUT_ENGINE_MEM_PERC        = 0.5%
PLAYOUT_ENGINE_CPU_PERC        = 0.0%
LIQUIDSOAP_PROCESS_ID          = 4362
LIQUIDSOAP_RUNNING_SECONDS     = 4234
LIQUIDSOAP_MEM_PERC            = 0.7%
LIQUIDSOAP_CPU_PERC            = 11.4%
MEDIA_MONITOR_PROCESS_ID       = 1489
MEDIA_MONITOR_RUNNING_SECONDS  = 121179
MEDIA_MONITOR_MEM_PERC         = 0.5%
MEDIA_MONITOR_CPU_PERC         = 0.0%
-- Your installation of Airtime looks OK!

Question : so what is the problem with the system function, and where is the rest of the values coming from as i am expecting the web browser to echo as shown by my commnad, and how do I fix it

PS: note I ran the PHP page and the command a few seconds apart so the values are a little off

Upvotes: 1

Views: 127

Answers (2)

complex857
complex857

Reputation: 20753

Those are ascii color codes, the service doesn't seem to detect if the calling terminal supports them or not. You can try to get rid of them with echo. You can try sed snippets like these.

Upvotes: 2

Jens Jensen
Jens Jensen

Reputation: 1118

Your program uses shell colors. The [1;32m is consumed by your shell, but not in verbatim output. See: https://unix.stackexchange.com/questions/43408/printing-colored-text-using-echo

Upvotes: 1

Related Questions