Search code examples
phplinuxshellexecshell-exec

echo exec working but exec not


I am using red hat enterprise edition n try making a simple php page..

When I try with ...

 // html code
 <?php
 echo exec(<cmd>); 
 ?>
// rest html code

Its working fine

but when tried with ...

 // html code     
 <?php
 exec(<cmd>);
 ?>
 // rest html code

Its not working

even a simple command like cat,ls,etc not working and also I tried 2 > &1 then no error is printed .

What could be the possible error ???


Solution

  • Docs:

    return a response from the command, you would need to print the response out as well

    Example:

    <?php
    $response = array();
    exec('whoami', $response);
    print_r($response,true);
    ?>