Use proc_open() instead of exec() to execute shell commands - this allows access to (amongst other things) any output written to STRDERR.