linux php shell execute,使用PHP腳本執行linux shell命令並在瀏覽器中顯示?

Executing unix shell commands using PHP Running shell commands using PHP script Execute a shell command through php and display it in browser? I have already referred to the above links. But, I'm experiencing an issue in displaying the linux shell command process in the browser. My linux command: top -n 1 and wanted to display them using php in the browser..

使用PHP執行unix shell命令使用PHP腳本運行shell命令通過php執行shell命令並在瀏覽器中顯示它?我已經提到了上面的鏈接。但是,我在瀏覽器中顯示linux shell命令進程時遇到了問題。我的linux命令:top -n 1,想在瀏覽器中使用php顯示它們。

myscript.php

$var = shell_exec('top -n 1');

echo "

$var
";

?>

Now, when I refresh my browser, I'm unable to see the output in the browser.

現在,當我刷新瀏覽器時,我無法在瀏覽器中看到輸出。

3 个解决方案

#1

Ok, I see your problem Rana. There some shell commands in linux needed to be set along with the TERM enviroment variable. top is one of them. In addition -b flag must be used in order to get the result from the output buffer, that in this case is the terminal... Try this code:

好的,我看到你的問題林蛙。 Linux中的一些shell命令需要與TERM環境變量一起設置。頂部就是其中之一。另外-b標志必須用於從輸出緩沖區獲取結果,在這種情況下是終端...嘗試此代碼:

$var = shell_exec('TERM=xterm /usr/bin/top -n1 -b');

echo "

$var
";

?>

#2

Since the user browser is not an interactive terminal then we have to execute your last command in every postback, in order to simlate the linux top command.

由於用戶瀏覽器不是交互式終端,因此我們必須在每次回發中執行最后一個命令,以便模擬linux top命令。

#3

Your script looks OK, let's make sure that your environment is correctly set up by changing the script to do something very simple. Try replacing all code with something like

您的腳本看起來沒問題,讓我們通過更改腳本來做一些非常簡單的事情來確保您的環境設置正確。嘗試用類似的東西替換所有代碼

echo "Hello World";

If that works, then some further debugging: Are you on a shared webhost where PHP is possibly configured to disable execution of scripts? See if shell_exec is disabled as detailed here (replace the string exec with shell_exec).

如果可行,那么進一步調試:您是否在可能配置PHP以禁用腳本執行的共享Web主機上?查看shell_exec是否已按此處詳細說明禁用(將字符串exec替換為shell_exec)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值