Runaway problem with FINDSTR "Line {nnn} is too long"

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MicrosoftIsKillingMe
Posts: 42
Joined: 11 Dec 2017 09:08

Runaway problem with FINDSTR "Line {nnn} is too long"

#1 Post by MicrosoftIsKillingMe » 05 Apr 2020 08:44

I have [at least one] irritating file,
C:\Windows\SoftwareDistribution\DataStore\DataStore.edb
that produces a runaway FINDSTR. (FWIW, the input file is over 2G.) Stderr begins with
FINDSTR: Line 2 is too long.
FINDSTR: Line 2 is too long.
FINDSTR: Line 2 is too long.
FINDSTR: Line 3 is too long.
FINDSTR: Line 3 is too long.
(etc.)
for hundreds of thousands before I break it. I have read that this happens whenever CRLF is not found for 8191 chars (I do not know if this is the culprit here). BTW, my search string is short and simple, like ABC, and I don't explicitly pipe or redirect. FWIW the irritating file has today's filedate (i.e. might be "open"). (* footnote)

Setting aside my use of FINDSTR on a file it's not designed for, etc., I'm looking for a general solution, so that my personal all purpose fs.bat avoids this - at least for this one file. Ideally, I would let this continue to arise for other files while I permanently steer around this one; and later as I discover new problem files like that, decide whether to selectively add them to a "skip list" of files or dirs. However since /D or /F or /G specify INclusion files or dirs, I don't know if they could be adapted to EXclude. (I also rejected throwing STDERR to NUL; besides, other valuable error lines would disappear.) So: I'm wondering if I can form an exclude list either on the command line (in a .BAT), or in EXCLUDE_FINDSTR.txt.

The only lame thing I've thought of is to 2>&1 and pipe everything to FIND /V for " is too long." but that breaks my intent to see when it's happening should it arise on another file somewhere. Besides, I'm afraid that even with this it would still spin for a seeming eternity processing those lines. (And by piping would I still see output "as it's occurring" or would it I have to wait to see normal output?)

Is there a practical general solution? Thx. You guys are geniuses.

BTW, I did read, as everyone with FINDSTR issues should, the "famous" dbenham workup
https://stackoverflow.com/questions/884 ... str-comman#
Also I considered adding to any of numerous stack/super/dostip/etc. FINDSTR discussions that I first researched but it seemed that this new thread was better for everyone.

* (My "runaway" BAT line is
findstr /m /s /i /c:%1 *.*
w/ arg ABC, which doesn't use redirection or piping, right? dbenham indicated that those drove the 8191 limit...)

pieh-ejdsch
Posts: 228
Joined: 04 Mar 2014 11:14
Location: germany

Re: Runaway problem with FINDSTR "Line {nnn} is too long"

#2 Post by pieh-ejdsch » 11 Apr 2020 09:11

This is definitely the 2 GB limit.
Since nothing can be written into the files with certainty, each file must be considered for itself.
A line must be searched for without a line end, and at the same time the error message must be evaluated.
You can even calculate how long this line is, for example. 9 * 8.192 = 73.719 to 82.888 characters long.
Depending on the case, you can now decide to search the file elsewhere.

Code: Select all

@echo off
setlocal
set "Errlog=%temp%\Errlog"
for /f "delims=" %%i in ('dir /s /b /a-d *.*') do ( set "error="
  findstr /mrv $ "%%~fi" >nul 2>"%Errlog%"
  if errorlevel 1 for /f "usebackQ delims=" %%a in ("%Errlog%") do ( set /a error=1
    echo  ERROR!
    echo  %%a
  ) >&2
  if NOT errorlevel 1 ( more +1 "%Errlog%" |findstr . 
    if NOT errorlevel 1 ( echo  Found multiple lines without line breaks!
      echo  %%i
      set /a error=1
  ) ) >&2
  if NOT defined error echo File %%i is ready to search for other string 
)

pause
Phil

Post Reply