Generate log files from Bat files

Many times a batch file needs to redirect output to a time stamped log file. The following example generates such a logfilename.

@echo off
 
for /f "tokens=1-4 delims=/ " %%a in ("%date%") DO set WD=%%a 
for /f "tokens=1-4 delims=/ " %%a in ("%date%") DO set MM=%%b
for /f "tokens=1-4 delims=/ " %%a in ("%date%") DO set DD=%%c
for /f "tokens=1-4 delims=/ " %%a in ("%date%") DO set YY=%%d
for /f "tokens=1-3 delims=: " %%a in ("%time%") do set HH=%%a
for /f "tokens=1-3 delims=: " %%a in ("%time%") do set MI=%%b
 
set LOGNAME=BUILD_%MM%%DD%%YY%_%HH%%MI%.log
echo Logfile : %LOGNAME%

Beyond this if you are compiling something which needs to go into %LOGNAME%, you use the » redirection operator

ccompile myfile.c >> %LOGNAME% 2>&1

batlogdate.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0