Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#1
Post
by foxidrive » 24 Feb 2014 19:36
Does this get a CR into a variable?
The question was asked elsewhere and I had never examined the technique - I can't seem to echo a CR into a file.
Code: Select all
::Define CR variable containing a carriage return (0x0D)
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
echo "%cr%">a.txt
echo a"%cr%b%cr%c%cr%d%cr%e%cr%f%cr%g%cr%"
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#3
Post
by foxidrive » 24 Feb 2014 20:34
Thanks Squashman, that's the tip!
Code: Select all
@echo off
setlocal enabledelayedexpansion
::Define CR variable containing a carriage return (0x0D)
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
echo "!cr!">a.txt
echo a"!cr!b!cr!c!cr!d!cr!e!cr!f!cr!g!cr!"
pause
-
jeb
- Expert
- Posts: 1063
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#4
Post
by jeb » 25 Feb 2014 17:31
Additional the cause why %CR% doesn't work.
It's the
parser phase just after the percent expansion of variables, it removes all CR's.
jeb