我想顯示一個shell腳本的輸出,就像它通過php腳本顯示在PuTTy或gnome-terminal中一樣。我試着用了shell_exec通過調用它:通過shell_exec中的自定義文件輸出shell輸出php
$output = shell_exec('echo "return value: ";foo=$(nameOfFileToExecute); echo $foo');
在哪種方式,我可以得到它存儲在Web服務器上的腳本的返回字符串?
我想顯示一個shell腳本的輸出,就像它通過php腳本顯示在PuTTy或gnome-terminal中一樣。我試着用了shell_exec通過調用它:通過shell_exec中的自定義文件輸出shell輸出php
$output = shell_exec('echo "return value: ";foo=$(nameOfFileToExecute); echo $foo');
在哪種方式,我可以得到它存儲在Web服務器上的腳本的返回字符串?
試試這個:
<?php
exec($your_shell_command_as_string, $arrayOfReturnedData);
// NOW YOU CAN ACCESS ALL THE VALUES RETURNED BY THE SHELL COMMANDS VIA THE ARRAY.
var_dump($arrayOfReturnedData); // DUMPS THE RESULTS OF THE SHELL COMMAND...
希望這有助於....
有可能是與nameOfFileToExecute
一個問題,所以儘量用全路徑/path/to/executable/nameOfFileToExecute
你必須給文件的完整路徑
並使用此2> & 1並知道錯誤
嘗試這樣的事情
$comando = "sh pathTofile/location/ftpgesdoc.sh";
if(exec("$comando 2>&1", $output, $return_var))
{
print_r($output);
echo "<br>";
print_r($return_var);
}
你嘗試'回聲$ output',或者如果你期待多行輸出嘗試'passthru',而不是'shell_exec' –
我做輸出回波在我phpfile 。它看起來像nameOfFileToExecute不會被執行(因此沒有輸出存儲在foo中)。 – PHPAtWork