How to retrieve PHP exec() error responses?

后端 未结 7 1612
孤街浪徒
孤街浪徒 2020-12-15 03:42

Below is the command I tried executing, without success:

exec(\'ln -s \' . PLUGIN_DIR . \'/.htaccess \' . ABSPATH . \'/.htaccess\');

When y

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 04:13

    The $output parameter does not appear to work if the calling program spits output to STDERR.

    A better way to handle this is to redirect the output from exec to a file and then display the contents of that file if there is an error condition.

    If $cmd holds the exec command add something like this:

    $cmd.=" > $error_log 2>&1"
    

    Then examine the contents of the filespec in $error_log for detailed info on why the command failed.

    Also note that if you fork this off with a & at the end of the command, an immediate check of the contents of $error_log may not reveal the log information - the script may check/process the file before the OS has finished.

提交回复
热议问题