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