0

I have a batch file named very_good02.bat. When I run it, it will show some progress info in command prompt.

I wish to auto write a log file that consists of all this progress information with the file name I keyed (which is very_good02).

I tried to ran it like this : very_good02.bat > very_good02log.txt the process is running in background where I can't see them in command prompt.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Chungz
  • 11
  • 2
  • 4
  • 1
    I think your questions is answered [here](https://stackoverflow.com/questions/503846/how-do-i-echo-and-send-console-output-to-a-file-in-a-bat-script). – GregP Mar 03 '19 at 16:25
  • thanks for the reply. But I am not quite understand about the answer on that particular post. I was thinking that if I ran the bat file. (very_good02.bat) with added some line to it inside the bat, it will auto generate a text file copy all the process information and save into a txt file name very_good02.txt. Sorry if I didn't explain it clearly. – Chungz Mar 03 '19 at 16:30
  • erm, perhaps something like select all, save as, "same file name".txt – Chungz Mar 03 '19 at 16:32
  • Possible duplicate of [How do I echo and send console output to a file in a bat script?](https://stackoverflow.com/questions/503846/how-do-i-echo-and-send-console-output-to-a-file-in-a-bat-script) – double-beep Mar 03 '19 at 18:26

1 Answers1

0

If I understand correctly, what you are seeking is a way to "tee" the pipeline to both the console and a log file.

The tee command has been in UNIX/Linux for a long time. No such thing in Windows cmd.exe. But, PowerShell does have Tee-Object. At a PowerShell command prompt, use help Tee-Object -full for more information.

powershell -NoLogo -NoProfile "& .\very_good02.bat | Tee-Object -FilePath 'C:\src\t\very_good02.log'"

Naturally, this is easier if your whole script is in PowerShell and not in cmd script language. You don't have to use PowerShell, but that is the clearly stated direction from Microsoft.

I am reminded that this can, actually, be done in a cmd .bat file script. Not easily, but it can be done. https://www.dostips.com/forum/viewtopic.php?p=32615#p32615 If anyone can do it in a .bat file script, Mr. Benham can.

lit
  • 14,456
  • 10
  • 65
  • 119