-1

I have PHP CLI application. I play sounds via mplayer on errors:

ob_start();
shell_exec('mplayer ./SadTrombone.mp3');
ob_end_Clean();

Sound is OK, but ob_end_clean() take no effect here - I get following output:

script output

iVenGO
  • 384
  • 1
  • 4
  • 17

1 Answers1

1

You can prevent the unwanted output from your command from appearing on the console, by redirecting the output from STDOUT and STERR to /dev/null, like so:

shell_exec('mplayer ./SadTrombone.mp3 > /dev/null 2>&1'); 
mti2935
  • 11,465
  • 3
  • 29
  • 33
  • **thnx!** [it worked](http://superuser.com/questions/71428/what-does-21-do-in-command-line). No idea why ob_* functions don't work here. – iVenGO Sep 24 '14 at 10:35
  • 1
    @iVenGO the reason it doesn't get caught by the output buffer is that the messages were written to the child process' stderr. If you want to capture that data in the string that `shell_exec()` returns, append `2>&1` to the command (this attaches stderr output to stdout). More info on [standard I/O streams](http://en.wikipedia.org/wiki/Standard_streams) and [I/O redirection](http://www.tldp.org/LDP/abs/html/io-redirection.html). Note also that `shell_exec()` is for returning the output to PHP, if you just want to execute the file and don't care about the output then use `exec()`. – DaveRandom Sep 24 '14 at 12:57