Goodnight! I can not display the result of exec. For example:

$output = array(); exec("crontab -l", $output); print_r($output, true); 

or

 echo exec("crontab -l"); 

and other variations.

Always displays emptiness. How can I display the result of the command?

Not crontab -l is needed. This is just for example.

    1 answer 1

    Most likely, you are not configured to output errors, so there are no messages that this feature is disabled due to security reasons. Calling disabled functions causes an E_WARNING error , which does not terminate the script.

    Functions: exec, system, passthru, readfile, shell_exec, escapeshellarg, escapeshellcmd, proc_close, proc_open, ini_alter, dl, popen, parse_ini_file, show_source.

    By default, disabled in PHP configuration. Since they are most often used in malicious scripts and pose a threat to the security of the system if used incorrectly or violate the general principles of security.

    In order to allow the execution of certain functions or all, you must remove the php.ini file from the settings file in the disable_functions of the file or comment out this line. This line looks like this:

     disable_functions = "exec,system,passthru,readfile,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,dl,popen,parse_ini_file,show_source,curl_exec,pcntl_exec,expect_popen" 
    • Thanks for the info, but no. There is nothing in disable_functions. When you turn on the display of errors, the void is also displayed. - Vasily Koshelev
    • @VasilyKoshelev Try echo exec("whoami"); , if it does not print anything, then try this: echo exec("whoami 2>&1"); - Firepro
    • Regularly displayed "apache". Maybe there are permissions here? ( Guessing from my closest position)) - Vasily Koshelev
    • @VasilyKoshelev Essentially, it should give an error if there is no access. If it were not executed at all, then in / etc / passwd the apache user would have / bash / false. Try running crontab -l 2> & 1, this allows you to forward the error stream to stdout - Firepro
    • Returns "no crontab for apache" - Vasily Koshelev