output on display and log file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
krunoo
Posts: 10
Joined: 21 Nov 2012 08:15

output on display and log file

#1 Post by krunoo » 18 Jun 2013 07:14

Hello,

is there a why to see output on screen and put logfile in txt file at the same time?

I have something like this:

for /f "tokens=1,2 delims= " %%a in (1.txt) do SOMETHING >> logfile.txt
...
...
...
for /f "tokens=1,2 delims= " %%a in (2.txt) do SOMETHING >> logfile2.txt

I dont want to use pause.

thx,
Kruno

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: output on display and log file

#2 Post by Endoro » 18 Jun 2013 09:13

please look here.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: output on display and log file

#3 Post by aGerman » 18 Jun 2013 11:23

I wrote it this way:

TEE.bat

Code: Select all

@echo off &setlocal EnableExtensions DisableDelayedExpansion
set "line=" &set "file=%~1"
if not defined file goto :eof
set "_me_=%0"
setlocal EnableDelayedExpansion
echo(!cmdcmdline!|findstr "\"/c\" !_me_!" >nul ||goto :eof
endlocal
for /f delims^=^ eol^= %%i in ('"more|findstr /n ^^"') do (
  setlocal EnableDelayedExpansion
  if defined line (
    echo(!line:*:=!
    >>"!file!" echo(!line:*:=!
  )
  endlocal
  set "line=%%i"
)


You could use it as follows:

Code: Select all

your command here|TEE "out.txt"


That's not foolproof but it's suitable to satisfy my needs.

Regards
aGerman

krunoo
Posts: 10
Joined: 21 Nov 2012 08:15

Re: output on display and log file

#4 Post by krunoo » 19 Jun 2013 00:17

Thank you Endoro and aGerman very much.

I test with TEE.bat and work very very nice...

You make my very hot day very pleasant. :)

Aacini
Expert
Posts: 1887
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: output on display and log file

#5 Post by Aacini » 19 Jun 2013 06:34

An equivalent but simpler solution, is this:

Code: Select all

your command here > out.txt & type out.txt

Post Reply