Is it possible to get the error text at the output of the exec() function, and not the code?

Example:

 cat: /file_path No such file or directory 

    1 answer 1

    It is possible, but for this, use the shell_exec function.

    It returns the full output as a string, which is what you need.

    You just need to add 2>&1 to output data to a variable:

     $output = shell_exec("cat /home 2>&1"); var_dump($output); 

    The output will be:

     string(27) "cat: /home: Is a directory" 
    • does not quite fit me, since the function does not return an array with the result as exec does. - quaresma89
    • + if you use the design plan | grep does not return anything at all, although there is an error about the non-existence of the file - quaresma89
    • one
      @ quaresma89 answer was given on the basis of the question - Yaroslav Molchan