Display program execution results to the screen and print them to the log file

Source: Internet
Author: User

If you print the execution result to a file, you will surely think of the output redirection character> or>, but the output redirection can only be output to the file or screen, and cannot be output at the same time. now we have the tee tool.

Simply put, the file display command ls

Root @ ubuntu :~ /Test_dis # ls | tee log_filelog_filereadmeuploadutilities

Execute Command

Ls | tee log_file

When ls is executed, use the MPs queue to send the content to tee for processing. Then, tee outputs the ls execution results to the screen and then outputs the results to the log_file file. If log_file does not exist, it is created and overwritten,

If you want to add the end of the file to log_file rather than overwrite it, you can add the-a parameter.

Ls | tee-a log_file

This will not overwrite the log_file.

 

This tool is linux. If you want to use it on windows, you need to install PowerShell.

 

Reference:

Http://en.wikipedia.org/wiki/Tee_ (command)

Http://codingstandards.iteye.com/blog/833695

Http://www.linuxidc.com/Linux/2006-09/124.htm

-------------------------------------------------

Http://superuser.com/questions/74127/tee-for-windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.