开发者

How to mirror terminal output to file without shell command?

开发者 https://www.devze.com 2023-04-10 09:44 出处:网络
I\'m putting the finishing touches of a project, and have a bit of a dilemma.Once all the data is gathered and statistics calculated, the results are then printed to the screen.However, in the program

I'm putting the finishing touches of a project, and have a bit of a dilemma. Once all the data is gathered and statistics calculated, the results are then printed to the screen. However, in the program, the user is given the option of saving all the output to a file. I'd like to print data to both the terminal and file with same formatting.

I considered doing a fork(), 开发者_StackOverflow社区but this is all one process and the data output is done just before the program termination. If I fork, then the child process will start executing from the beginning, and implementing successfully would result in a not so minor rewrite of 500+ LOC.

I covered roughly this exact same topic last semester, but left my unix programming book at home and none of the examples I've found fit my needs.


Consider piping your output through the tee command, which writes to stdout and a file.

0

精彩评论

暂无评论...
验证码 换一张
取 消