Computer Hope

Microsoft => Microsoft DOS => Topic started by: srujana on November 29, 2011, 09:15:26 AM

Title: how to echo line both on screen and text file
Post by: srujana on November 29, 2011, 09:15:26 AM
I want to display the output both on screen and log.txt file

like

echo %%a > log.txt

this is redirecting to txt file. i want on screen as well

is ther any way?
Title: Re: how to echo line both on screen and text file
Post by: Raven19528 on November 29, 2011, 09:25:42 AM
The only way I know of is to echo the line twice.

Code: [Select]
echo %%A > log.txt
echo %%A

I know it is an extra line, but is there any reason this won't work?
Title: Re: how to echo line both on screen and text file
Post by: Squashman on November 29, 2011, 05:59:52 PM
Unlike most Nix systems there is not a native way to do this in batch.  You can use the TEE command on most NIX operating systems to do this.  I believe there is a Win32 port of it if you really want to do this.
Title: Re: how to echo line both on screen and text file
Post by: Salmon Trout on November 30, 2011, 11:32:12 AM
Unlike most Nix systems there is not a native way to do this in batch.  You can use the TEE command on most NIX operating systems to do this.  I believe there is a Win32 port of it if you really want to do this.

There are plenty of Tee.exe programs around, not to mention any number of Tee.bat. Tee.cmd and Tee.vbs scripts. The most cursory of Google searches will turn up plenty of results, which it would be both tedious and redundant to reproduce here. In particular searching the Google archive of alt.msdos.batch.nt using intelligently chosen search terms is a fruitful method of finding solutions.

If the OP is using a business or school system where installation of third party executables is not allowed, then a cmd or vbs approach may be the only way.


Title: Re: how to echo line both on screen and text file
Post by: _her0brin3 on December 16, 2013, 09:54:18 AM
You can use:

echo %%a >> log.txt
echo %%a

in one line, maybe use a pipe, fork, or do:

echo %%a >> log.txt && echo %%a

Thats your best option