ECHO commands to a batch file

September 28, 2010 at 14:31:14
Specs: Windows XP, 2GHz/2GB
I need to echo two lines to set a variable for time format to be used as a timestamp. Since these lines are part of a FOR loop with a DO command to generate a number o batch files, I cannot figure out how to escape the two lines below:

echo set cur_hh=%%time:~0,2%% >> file.bat
echo if %%cur_hh%% lss 10 (set cur_hh=0%%time:~1,1%%) >> file.bat
echo echo %%cur_hh%%%%TIME:~3,2%%^>^>file.txt >> file.bat

Thanks


See More: ECHO commands to a batch file

Report •


#1
September 29, 2010 at 18:04:45
Since these lines are part of a FOR loop with a DO command


If you are inside parens(code block) then you need to at least escape the closing paren, personally I tend to also escape the opening one:

echo if %%cur_hh%% lss 10 ^(set cur_hh=0%%time:~1,1%%^) >> file.bat


Be aware the %time% varies based on user settings.


Report •

#2
September 29, 2010 at 20:03:14
Hi,

Thank you for the reply. I used a slightly different approach and it seems to work well:

echo set tmp_time=%%time:~-11,2%%%%time:~-8,2%%>>file.bat
echo set tmp_time=%%tmp_time: =0%%>>file.bat


Report •

Related Solutions


Ask Question