tags:

views:

44

answers:

2

Hi to all again,

I have again another trouble with using exec in php
my os is suse linux and I am using php 5.1.2

Somehow my output is being trimmed when i use exec()

in linux

~ -> ps -ef | grep java
root      3548     1  0 Aug05 ?        00:00:01 /usr/java/jdk1.5.0_13//bin/java -server -Djava.awt.headless=true -Xms512m -Xmx512m -XX:NewSize=224m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 -XX:+UseParallelGC -jar /jfe-server.jar start
psinl    14811     1  0 09:12 ?        00:00:01 /usr/java/jdk1.5.0_13//bin/java -server -Djava.awt.headless=true -Xms512m -Xmx512m -XX:NewSize=224m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 -XX:+UseParallelGC -jar jfe-server.jar start
psinl    18164 18080  0 16:20 pts/1    00:00:00 grep java

but when output to web via

<div>Checking whether JFEServer has been started</div>
<div><pre><?php exec('ps -ef | grep java',$output,$result);
print_r($output); ?></pre>
</div>
</br>

And my output on the web

Checking whether JFEServer has been started

Array
(
    [0] => root      3548     1  0 Aug05 ?        00:00:01 /usr/java/jdk1.5.0_13//bin/java
    [1] => psinl    14811     1  0 09:13 ?        00:00:01 /usr/java/jdk1.5.0_13//bin/java
    [2] => psinl    18069 14271  0 16:20 ?        00:00:00 sh -c ps -ef | grep java
    [3] => psinl    18071 18069  0 16:20 ?        00:00:00 grep java
)

Why is that php has automatically trimmed off my output even I didnt want it to?

+1  A: 

You could use passthru, which passes the output of a command directly to the clients browser.

<div>Checking whether JFEServer has been started</div>
<div><pre><?php passthru( 'ps -ef | grep java', $result ); ?></pre></div>
<br />

If that doesn't help, you should look into the documentation of ps, if it tests the standard output terminal type (e.g. file/pipe/terminal). If it does so, it could be trimming it to some default width if it can't determine the actual terminal width. On my debian based server it does. The correct command on my machine is:

<div>Checking whether JFEServer has been started</div>
<div><pre><?php passthru( 'ps -efww | grep java', $result ); ?></pre></div>
<br />
haggi
A: 

php did not trim you output, the browser did. check the original output by Right click -> View Page Source on browser.

ideawu