Fixed output php exec

I am again having another problem using exec in php
my os is suse linux and I am using php 5.1.2

Somehow my output is clipped 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 accessing the network through

<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 conclusion on the Internet

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 did this php automatically disable my output, even I didn’t want it?

+3
source share
4 answers

You can use passthru, which passes the output of the command directly to the client browser.

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

, ps, ( , //). , , . debian . :

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

, PHP exec. : exec()

: exec('ps -ef | grep java > /tmp/mytmpfilename.txt')

... file_get_contents()

: var_dump(file_get_contents('/tmp/mytmpfilename.txt'));

edit: (), LOT , , .

+1

-w, ps Centos 6.2. , , script.

In a TTY session, ps will not clip the output, but in other circumstances (depending on the variable TERMit will be. You can also explicitly set it unlimited by adding -ww.

ps man pages were the key for me on this one.

+1
source

php did not trim your output, the browser did. check the initial result by right-clicking → View page in browser.

-1
source

Source: https://habr.com/ru/post/1761266/


All Articles