通过php中的shell_exec从自定义文件输出shell输出
I would like to display the output of a shell script like it is shown in PuTTy or gnome-terminal via a php-script. I tried using shell_exec by invoking it:
$output = shell_exec('echo "return value: ";foo=$(nameOfFileToExecute); echo $foo');
In which way can I get the return string of the script which is stored on the webserver?
我想显示一个shell脚本的输出,就像它在PuTTy或gnome-terminal中通过php显示的那样 -脚本。 我尝试通过调用它来使用shell_exec: p>
我可以通过哪种方式获取存储在Web服务器上的脚本的返回字符串? p>
div> $ output = shell_exec('echo'返回值:“; foo = $(nameOfFileToExecute); echo $ foo'); code> p>
Try this instead:
<?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...
Hope this helps....
There might be a problem with the nameOfFileToExecute
, so try using the full path /path/to/executable/nameOfFileToExecute
you have to give the full path to file
and use this 2>&1 and know the error
try something like this
$comando = "sh pathTofile/location/ftpgesdoc.sh";
if(exec("$comando 2>&1", $output, $return_var))
{
print_r($output);
echo "<br>";
print_r($return_var);
}