[Hint] Reading STDERR output in PHP

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!

2 Responses to “[Hint] Reading STDERR output in PHP”


  1. 1 opi

    Mah, you could just ask me! ;-)

  2. 2 Filip Tepper

    @opi:

    That was one of those really-old-ones. ;-)

Leave a Reply