Page 1 of 1

Win7 FOR fails to parse correctly if 0Ah in parsed DSN

Posted: 30 Jan 2014 22:53
by MtheK
For some reason, using this command:

Code: Select all

for /f "usebackq tokens=1,2* delims= " %%i in (`type COUNTER.txt`) do set COUNTERrc3=%%i


against file COUNTER.txt which contains:
0x0000020A 0586 6.1 2 ????##
where '????' is 0A020000h and '##' is 0D0Ah (CRLF)

the FOR fails to parse the 1st field correctly and does this:
set COUNTERrc3=0x0000020A
set COUNTERrc3="un-printable character"

which causes all sorts of problems. In my case, I had to set
a special ERRORLEVEL in my MASM program if a 0Ah is in any of
the 4 bytes in the ???? field that is in binary format, in order
to bypass running this FOR command in its' .bat.

Is this a FOR restriction? I first tried adding a 0Ah in the "delims= "
field after the space, but the FOR then failed syntax checking.

Comments?

Re: Win7 FOR fails to parse correctly if 0Ah in parsed DSN

Posted: 31 Jan 2014 10:03
by carlos
MtheK please you can post a hexdump of COUNTER.txt ?

Re: Win7 FOR fails to parse correctly if 0Ah in parsed DSN

Posted: 31 Jan 2014 10:54
by Endoro
try this:

Code: Select all

for %%a in (COUNTER.txt) do fsutil file createnew COUNTER.tmp %%~za
fc COUNTER.txt COUNTER.tmp /b | findstr /c:"00000016: 0A" /c:"00000017: 0A" >nul&& echo 0ah found || echo 0ah not found
del COUNTER.tmp

Please note, this is an example. The parameter's values may vary.

Re: Win7 FOR fails to parse correctly if 0Ah in parsed DSN

Posted: 31 Jan 2014 15:56
by MtheK
This is my test input:
00000000 30783030303030323039203035383620 0x00000209 0586
00000010 362E31203220090200000D0A 6.1 2 ..

Fsutil requires to be run ELEVATED, but, in any case:
h:\d\TOOLS\MYPROGS\COUNTER>fsutil file createnew COUNTER.tmp 28
File h:\d\TOOLS\MYPROGS\COUNTER\COUNTER.tmp is created
h:\d\TOOLS\MYPROGS\COUNTER>fc COUNTER.txt COUNTER.tmp /b | findstr /c:"00000016: 0A" /c:"00000017: 0A" 1>nul && echo 0ah found || echo 0ah not found

0ah found

yet this .tmp file is NULLS (same record length), so the FOR parsed nothing:
00000000 00000000000000000000000000000000 ................
00000010 000000000000000000000000 ........

At any rate, I circumvented this problem by using the .tmp suggestion; I changed my MASM program to create a DUP .tmp file, but only containing the string I want to parse w/the trailing blank, w/o the hex field. FOR then works as expected. Thankx...