asked on
Add option to display to screen in addition to logging a file in a .bat routine
I would like to change this .bat file so that in addition to creating a log file that I am also able to see the activity displayed on my monitor as the script is running.
What change would I need to make to this script?
Thanks in advance for your assistance.
E:\Users\Users1\Scripts\Go.bat>"E:\Users\Users1\Logs\WithGobatlog.log" 2>&1
ASKER
Qlemo, thanks you, when I use the tee.cmd nothing displays to the screen.
ASKER
Thanks oBdA for the various suggestions.
Apart from the UnixTee utility, the first method might take me a long time to recode, and the second PowerShell method works well.
With PowerShell unfortunately I colour coded some of the echo lines and of course I am not seeing those when using PowerShell.
ASKER
Qlemo, it seems that none of the methods work for me, either it blips or it runs but it does not output to the screen.
Be aware that the escape codes will end up in the log as well (and the colors will work for the log, too, when viewed in the console).
@echo off
setlocal
REM Set the variable esc to Char(27)
powershell.exe -Command "Set-Content -Value ([char]27) -LiteralPath '%Temp%\esc.txt'" >NUL
for /f %%a in ('type "%Temp%\esc.txt"') do set esc=%%a
echo Hello World
echo %esc%[92mHello World%esc%[0m
ASKER
Thank you. For the Tee-Object to work does tee.exe from https://unxutils.sourceforge.net need to be installed?
And I am running a .bat as opposed to a .cmd file would that make a difference?
Just in case, as far as tee.exe is concerned: tee.exe is a stand-alone application; you can just extract it from the archive and put it in any folder. No need to "install" anything.
ASKER
Thanks oBdA, actually when I opened the PowerShell file and ran it within, that's when I didn't see the colours. But when I right clicked on the file and ran it with PowerShell, the colours did show. I presume when I call on it within a .bat file this will be ok.
Ok and thanks very much for the information about the tee.exe as well, much appreciated.
ASKER
Thanks again oBdA, this works. My only loss during this process using the PowerShell script and the Tee Object is that where I have 'cls' in the script, that does not actually refresh when it's running this way. However at least I get the log which is what I really needed. Many thanks.
No clue why my suggestions didn't work. It does for me.
There is nothing in-built to allow for duplicating a file stream. A Windows port of the Unix TEE command is what I used most in the past, but you can also use something like:
Open in new window
Or create a .cmd/.bat file tee.cmd
Open in new window
and use it like so:
Open in new window