Page 1 of 1
batch on-screen and logged to textfile?
Posted: 10 Feb 2009 12:45
by simpleton
I want to log my batch to a text file, and still have the live version showing on screen. I've done some research on it, and cant find anything. Is this even possible? It seems like you can either have it on screen-live, or pipe it to text.
I'm trying to catch an error that is popping up, and I need to keep the live version so that it shows onscreen. So, if someone were to cancel the batch, I can still check the log.
Any ideas? I'm stuck on this one.
Posted: 10 Feb 2009 14:58
by RElliott63
This is probably more than you're looking for, but it's a start:
I usually just log everything with a call to a :JobLog procedure
This allows me to do something like...
Code: Select all
Set JobLog=\BKOffice\CSK\CSKZip.Log
...
Call :JobLog H
If NOT Exist FileName.exe (
Call :JobLog D " *** ERROR *** "
Call :JobLog D "FileName.exe Does NOT Exist!"
Call :JobLog D "Place the file, then try again! "
Goto Exit
)
...
Call :JobLog B
Call :JobLog D " -- Begin Prefix Processing -- "
Call :JobLog B
...
CD %OldDir%
Call :JobLog B
Call :JobLog D " -- Begin Archive Processing -- "
Call CSKArch.exe
Call :JobLog D " -- End Archive Processing -- "
Call :JobLog B
That way, everything I want to log echos the output for visual confirmation
Code: Select all
:: Do the Job Log Work
::============================================================================::
:JobLog
:: Detail Line
If /I {%1} equ {D} (
Echo %~2
Echo %~2 >> %JobLog%
Goto:EOF
)
:: Blank Line
If /I {%1} equ {B} (
Echo;
Echo; >> %JobLog%
Goto:EOF
)
:: Draw a line
If /I {%1} equ {L} (
Echo *=========================================================*
Echo *=========================================================* >> %JobLog%
Goto:EOF
)
:: Ending
If /I {%1} equ {E} (
Echo %Date% -- %Time%
Echo Job Complete!
Echo;
Echo *=========================================================*
Echo %Date% -- %Time% >> %JobLog%
Echo Job Complete! >> %JobLog%
Echo; >> %JobLog%
Echo *=========================================================* >> %JobLog%
Goto:EOF
)
:: Header
If /I {%1} equ {H} (
Cls
Echo;
Echo *=========================================================*
Echo Job Date: %Date%
Echo Time: %Time%
Echo PODS: %GetPODs%
Echo Sett: %GetSETT%
Echo EJStore: %ejSTORE%
Echo EJDate: %ejDATE%
Echo Zip Prg: %ZipPrg%
Echo *=========================================================*
Echo;
Echo; >> %JobLog%
Echo *=========================================================* >> %JobLog%
Echo Job Date: %Date% >> %JobLog%
Echo Time: %Time% >> %JobLog%
Echo PODS: %GetPODs% >> %JobLog%
Echo Sett: %GetSETT% >> %JobLog%
Echo EJStore: %ejSTORE% >> %JobLog%
Echo EJDate: %ejDATE% >> %JobLog%
Echo Zip Prg: %ZipPrg% >> %JobLog%
Echo *=========================================================* >> %JobLog%
Echo; >> %JobLog%
Goto:EOF
)
Goto:EOF
The nice part about this is... your log file looks EXACTLY like what they see on the screen!
HTH
-Rick
Posted: 17 Feb 2009 18:57
by jaffamuffin
mm. That may work, but don't have time to uderstand exactly what it doing..
what I have done in the past is to get a copy of tail.exe you can get this from the gnu utils / unix tools and then run your script with myscript.bat > log.txt and then in another window type tail -f log.txt and it will just act as a monitor (tail -f is follow)
If you script requires input, you need to key it in the first window which is tricky cos it doesn't display anything.
It can be handy for debugging as well as you can leave the tail -f command running, and it will just display whatever appears in the log file. (multiple runs of the scripts etc)
Posted: 20 Mar 2009 09:46
by JustJoe
Greetings:
Give tee (Unix util that forks stdout between the console and a file) a try. Yes it has been ported to DOS/Winblows.
Google is your friend
cheers
Posted: 23 Mar 2009 07:44
by simpleton
Nice. That is quite helpful!!