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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MtheK
Posts: 5
Joined: 22 Jan 2014 07:32

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

#1 Post by MtheK » 30 Jan 2014 22:53

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?

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

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

#2 Post by carlos » 31 Jan 2014 10:03

MtheK please you can post a hexdump of COUNTER.txt ?

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

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

#3 Post by Endoro » 31 Jan 2014 10:54

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.

MtheK
Posts: 5
Joined: 22 Jan 2014 07:32

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

#4 Post by MtheK » 31 Jan 2014 15:56

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...

Post Reply