1

I'm running a bat file to do a backup. I have it set to create a log file of the process by adding this to the top of the bat file.. (which I got from an answer on this site)

@Echo off
SET LOGFILE=MyLogFile.txt
call :Logit >> %LOGFILE% 
exit /b 0

Now, I'd like the bat file to visually run the same it was before. I need the end user to be able to see what it's doing and make choices at menus in the bat file. However, this code to create the log obviously re-directs all that text to the log file.

So, I get a log file that just starts with a menu asking the user to choose what to do and then nothing else.

How do I do it so I get my log file but also the on-screen output for the user?

Thanks in advance!

Chris
  • 31
  • 4
  • if you prefer a pure batch solution without additional utilities, see [here](http://stackoverflow.com/a/15553922/2152082). Not quite as elegant as a `tee` utility (there are many of them in the internet), but native. – Stephan Jul 12 '15 at 07:54

2 Answers2

1

Try like that :

@Echo off
SET LOGFILE=MyLogFile.txt
call :Logit
call :Logit >> %LOGFILE% 
exit /b 0

:Logit
ping www.google.com

or like this one :

@Echo off
SET LOGFILE=MyLogFile.txt
call :Logit & call :Logit >> %LOGFILE% & Start %LOGFILE%
exit /b 0

:Logit
ping www.google.com
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • Thanks for the quick answer! That almost works. The problem is I'm running a backup through a bat file. If I run the backup, then the log, it's not giving me an accurate log since it's not sending anything that was already backed up. And it would have to run twice to get the end result which isn't ideal. Is there any way to have them run side by side? Copy a file, add to the log, on to the next file? – Chris Jul 09 '15 at 19:05
  • So depends how to write your function Logit ? Can you edit your first post and add the code for the backup ? – Hackoo Jul 09 '15 at 20:01
0

Use this utility https://code.google.com/p/wintee/

(Brian Rasmussen's answer to the same question asked 16 years ago, please google first...) Displaying Windows command prompt output and redirecting it to a file

Hackoo's answer will call Logit twice, which is clearly not what you want.

Another solution would be to edit the .bat file so that it only writes to the log file what it needs to, and displays on the screen what the user needs. (Those two sets might overlap, so in that case, if it's just echoing, echo it twice, once to the log file, once to the screen.)

Community
  • 1
  • 1
John P
  • 1
  • 2
  • You don't think I Googled first? Not every Googling will lead you to what you want. Sometimes you still need some help. And, thank you. I'll check it out – Chris Jul 09 '15 at 19:49