I'm writing a console app using Symfony 2 Console Component, and I want to run a console clear command before (or as) the first line of my app.
I have done some research and am struggling to find if this is possible.
I have been looking for similar functionality. There is nothing built-in to the symfony console that can clear the screen as far as I can tell, but you can still achieve the clear behavior by using the escape code for resetting the terminal like so:
$output->write(sprintf("\033\143")); See the post "Clear the Ubuntu bash screen for real" and "What commands can I use to reset and clear my terminal?" for a more extensive explanation of the codes, and this symfony console pull request, where I got the code from, that attempted to emulate the clear functionality.
shell_exec('<any terminal command>') it did not work for me for clearing the terminal with a clear. But sending \033\143 to the output worked, which I think is the escape code for CTRL + C on a mac.sprintf actually required at this point?