Re: logging batch files

From: Matthias Tacke (Matthias_at_Tacke.de)
Date: 04/01/04


Date: Thu, 1 Apr 2004 19:22:21 +0200


"Rob P" wrote:
>"Joe Vaughan" <jvaughan@locktonrisk.com> wrote in message
>news:171cb01c417ef$edeea880$a101280a@phx.gbl...
>> Is there a way to log everything from the beginning of a
>> batch file to the end while it processes? I want to
>> capture the progress of batch files in a log. Any idea
>> how?

>Jerold replied to my similar post several days ago with the following
>information. It was exactly what I was looking for.
>
>@ECHO ON
>call :Logit>>batch.log 2>&1
>exit /b 0
>:Logit
>COMMAND 1
>COMMAND 2
>ETC
>
That is a really nice trick from Jerold. This extends it a bit:

@echo off
if /I "%1" NEQ "/log" goto :LogIt
set LogFil=%~dpn0.log
shift
echo on
call :LogIt %1 %2 %3 %4 %5 %6 %7 %8 %9 >%LogFil% 2>&1
goto :eof
:LogIt
::your normal batch code

Drawback of this prependable fragment is, it garbles the %0 value and
the /log argument which enables logging has to be the first.
If the count of needed arguments is greater than 9 it won't work either.
The log file is created in the folder where the batch resides.
The log file name can easily be extended with %date%.

Otherwise prepend your batch with this snippet and you have a logging
option.

-- 
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm  XP>HH ntcmds.chm


Relevant Pages

  • Re: Batching Updates?
    ... If you batch run them, they will automatically wait for one to finish before ... Echo Applying IE 5.5 Post-SP2 Hotfixes to system. ... Echo Reboot to activate changed files. ... >>the network login script or a batch file run on the ...
    (microsoft.public.security)
  • Re: Multi-zip files -- Windows server
    ... native DOS versions). ... TO BATCH OR NOT TO BATCH ... and using a batch file to try and solve the problem... ... The IBM PC operating system command line is a most ...
    (comp.sys.cbm)
  • Re: EWF RAM
    ... Do you mean it is running the stress test fine locally on the device? ... If it does and the issue has no repro, you should move to use local batch file approach in your support scenario. ... >> A tech plugs into it with laptop and remote desktops to it. ...
    (microsoft.public.windowsxp.embedded)
  • Re: Windows "Scheduled Task Wizard..."
    ... Do you know any links at Microsoft documents related to the batch file ... command name to get started. ... VB Script and any other Microsoft scripting languages have nice ...
    (microsoft.public.windows.server.general)
  • Re: Command prompt tool to minimize a command window AFTER it starts?
    ... > running CMD.exe in an open window which has the annoying habit of coming ... > minimize it -- my intent is to run it as the first line of the batch. ... You can rewrite the main Batch file as a Subroutine shell, ... ECHO command): ...
    (microsoft.public.win2000.cmdprompt.admin)