Problem with underscore in findstr literal string

B

borgulyp

Hi

I've written a series of batch jobs, where one job writes into a log
file (success/failure) and the next one then checks to see if job1 was
successfull. The batch is to process a series of reports. I am using
the path to the report to find the right entry in the log file.

Now the path has changed and newly includes an underscore (_)
character. Since then, the findstr does not work as expected anymore. I
can find no reference that _ is some kind of special character. If I
escape the _ (manually, that is), the findstr works.

=== Script ===
set TARGETREPORT=\\vfbdn114\eglch$\_Projekte\MidOffice
Report\Testing\RC Energy per Book.xls
set STRING=%TARGETREPORT% Status: SUCCESS
findstr /c:"%STRING%" "c:\temp\Reports_20050709_085932.log"
IF %ERRORLEVEL% EQU 1 goto failure
IF %ERRORLEVEL% EQU 0 goto end
:failure
ECHO fail=%ERRORLEVEL%
:end
ECHO ok=%ERRORLEVEL%
== End Script ===

The complete string in the log file is

"09.07.2005 17:52:44 Report generation
\\vfbdn114\eglch$\_Projekte\MidOffice Report\Testing\RC Energy per
Book.xls Status: SUCCESS "

If I change the first line of the script to
set TARGETREPORT=\\vfbdn114\\eglch$\_Projekte\MidOffice
Report\Testing\RC Energy per Book.xls

Any ideas ?
Thanks
 
J

Jerold Schulman

Hi

I've written a series of batch jobs, where one job writes into a log
file (success/failure) and the next one then checks to see if job1 was
successfull. The batch is to process a series of reports. I am using
the path to the report to find the right entry in the log file.

Now the path has changed and newly includes an underscore (_)
character. Since then, the findstr does not work as expected anymore. I
can find no reference that _ is some kind of special character. If I
escape the _ (manually, that is), the findstr works.

=== Script ===
set TARGETREPORT=\\vfbdn114\eglch$\_Projekte\MidOffice
Report\Testing\RC Energy per Book.xls
set STRING=%TARGETREPORT% Status: SUCCESS
findstr /c:"%STRING%" "c:\temp\Reports_20050709_085932.log"
IF %ERRORLEVEL% EQU 1 goto failure
IF %ERRORLEVEL% EQU 0 goto end
:failure
ECHO fail=%ERRORLEVEL%
:end
ECHO ok=%ERRORLEVEL%
== End Script ===

The complete string in the log file is

"09.07.2005 17:52:44 Report generation
\\vfbdn114\eglch$\_Projekte\MidOffice Report\Testing\RC Energy per
Book.xls Status: SUCCESS "

If I change the first line of the script to
set TARGETREPORT=\\vfbdn114\\eglch$\_Projekte\MidOffice
Report\Testing\RC Energy per Book.xls

Any ideas ?
Thanks

As an experiment change the findstr to
findstr /L /c:"%STRING%" "c:\temp\Reports_20050709_085932.log"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top