Reputation: 51
hi I am trying to use TYPE command to save output to the file for example:
type %Destination%\buildInfo.xml >> Logs\%Envlog% %Date% %Time%
where Envlog = logging.log
this is not happening do you know why?
Please note that buildInfo.xml is never empty.
Upvotes: 2
Views: 1892
Reputation: 41287
%date%
and %time%
can change with the users preferences and locale.
The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
echo fullstamp: "%fullstamp%"
pause
Upvotes: 0
Reputation: 55467
Try adding quotes:
type %Destination%\buildInfo.xml >> "Logs\%Envlog% %Date% %Time%"
However, I don't think this will give you what you want, because this will end up as something like "Logs\logging.log 20131231 04:33"
Using this answer as a reference, you could do something like this (I didn't use the environment variable in this case, not sure you need it if the name is always going to be logging.log):
set hr=%time:~0,2%
if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
type %Destination%\buildInfo.xml >> Logging_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%.log
Upvotes: 3