I just recently ran into this same problem in trying to run phpunit from the command line in git bash on windows 7. After conducting some research into possible various solutions I decided to share the solution I chose to implement for myself, here.
You can filter out the ANSI color control characters from git bash. Create a file named phpunit
(note: the actual phpunit script wasn't in my path and I was mainly running unit tests from intellij only) and put it anywhere in your $PATH
(I prefer ~/bin
myself but there's no rule about that):
#!/bin/sh
/path/to/phpunit "$@" 2>&1 | perl -pe 's/(?<=\e\[)2;//g'
The "$@"
tells bash to take the rest of the arguments passed to the script and forward them to phpunit. The 2>&1
redirects stderr to stdout, ensuring that any control characters generated in producing error output will also be filtered out.
Finally, all of the output produced by phpunit is piped through perl and run through the regular expression 's/(?<=\e\[)2;//g'
, which strips out the control characters.
The end result is that phpunit runs just fine, regardless of what <phpunit colors=""
setting you are using.
Hope this helps!