Recently I was working on a command line PHP script. I know that there are better ways to do things, but I didn’t want to use any other language, since most developers in our company know mainly PHP.
The script exec’s MySQL command to execute a batch of SQL queries. I also wanted the script to mail the error messages. mysql redirects error messages to STDERR - but STDERR is by default not available in exec’s output argument.
Walkaround is simple:
exec('your_command 2>&1');
Works!