new findstr bug
Posted: 16 Jun 2013 15:29
Dear DosTips,
I tried piping a single character into findstr using set /p, type, and findstr itself. The results were the same: absolutely nothing! findstr silently gobbled it up.
But it gets worse. I piped a multi-line text file into findstr that didn’t end with a newline and had a single character on the last line. You guessed it—findstr omitted the single-character last line.
The only exception is if the single character is a Line Feed (ASCII 10).
Kudos to anyone who can find a way to exploit this bug. Isn’t it wonderful that Batch can still surprise us after all this time?
- SB
PS: I’m using Windows 7 Home Premium 32-bit, fwiw.
I tried piping a single character into findstr using set /p, type, and findstr itself. The results were the same: absolutely nothing! findstr silently gobbled it up.
Code: Select all
> <nul set /p "=#" | findstr /n "^"
(no output)
> <nul set /p "=##" | findstr /n "^"
1:##
But it gets worse. I piped a multi-line text file into findstr that didn’t end with a newline and had a single character on the last line. You guessed it—findstr omitted the single-character last line.
Code: Select all
> type sample.txt
ordinary line<CR><LF>
#
> type sample.txt | findstr /n "^"
1:ordinary line<CR><LF>
The only exception is if the single character is a Line Feed (ASCII 10).
Kudos to anyone who can find a way to exploit this bug. Isn’t it wonderful that Batch can still surprise us after all this time?
- SB
PS: I’m using Windows 7 Home Premium 32-bit, fwiw.