Jun 22, 2017

output a data stream to screen and a file using tee

In linux, process an incoming serial data stream (from program a.out) which appears on screen (stdout) and route to a file at the same time.
./a.out | tee > logfile.txt
It is not smooth, as the terminal is buffering data. To change that, use 
unbuffer ./a.out | tee > logfile.txt
To use unbuffer, you must install the "expect" package*


References

https://stackoverflow.com/questions/11337041/force-line-buffering-of-stdout-when-piping-to-tee 

*to get it on Mac unix, the package installer recommended is homebrew.
1) install homebrew if you don't have it.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
2) Search for the desired package "expect"
brew search expect
 3) it's found, so install it.
brew install expect

No comments: