Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect console output to file and STILL get it in the console?

Tags:

I want to run an ANT script which prompts the user for input, so it needs to be interactive through the console. at the same time I want to log the console content to a log file. I know I can use ant >build.log 2<&1 which will redirect to file, but leave the console empty.

So, how can that be done? needed on windows and unix.

like image 978
erezul Avatar asked Sep 30 '11 15:09

erezul


People also ask

How do I capture a console output to a file?

To redirect the output of a command to a file, type the command, specify the > or the >> operator, and then provide the path to a file you want to the output redirected to. For example, the ls command lists the files and folders in the current directory.

How do I redirect standard output to a file?

Redirecting stdout and stderr to a file: The I/O streams can be redirected by putting the n> operator in use, where n is the file descriptor number. For redirecting stdout, we use “1>” and for stderr, “2>” is added as an operator.

How do I redirect output to a file and screen in Linux?

Redirecting output to a single file and screen: You can also append the redirected output by utilizing the “-a” or “–append” option with the tee command. -a or –append option allows tee command to append files rather than overwriting the file's content.


1 Answers

Use tee.

ant 2>&1|tee build.log 

tee.exe is also available for Windows from http://unxutils.sourceforge.net/

like image 79
lavinio Avatar answered Sep 19 '22 12:09

lavinio