문제

I am writing a small script for watchr that runs my PHP unit tests.

Current script runs tests using system() and displays them colored.

I am trying to add libnotify functionality, but for that I need to parse the output and match against regexp, so that notification will either display green or red.

system() doesn't return output, %x does return, but puts p doesn't display colors, which I need to quickly see which test failed. One option would be to run tests twice - once for display in terminal window, and second time for checking which notification to show, but I would rather avoid it.

도움이 되었습니까?

해결책

puts does display colors. The problem is when you run with %x your PHP test runner will most likely turn off colored output because it thinks it's not running under a terminal.

The same thing happens if you do run_php_test | less in the shell. To fix it you need to force colored output on the PHP test runner.

EDIT

Easiest way to run a subprocess with pty:

require 'pty'
puts PTY.spawn('run_php_test')[0].read
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top