Log Parser and Batch Files
by Željko Filipin
I am using Log Parser to parse log files. I parse a lot of files and I wanted to make a batch file that will do it for me.
I pasted my commands to a batch file, executed it, and to my surprise, it would parse the files but would not find anything.
This is content of my batch file:
LogParser "SELECT text FROM errors.log WHERE text LIKE '2008-%'"
When I execute it, it does not find anything:
C:\>parse_logs.cmd
C:\>LogParser "SELECT text FROM errors.log WHERE text LIKE '2008-'"
Statistics:
--
Elements processed: 34
Elements output: 0
Execution time: 0.02 seconds
When I executed the command from command prompt, Log Parser would find what I was looking for:
C:\>LogParser "SELECT text FROM errors.log WHERE text LIKE '2008-%'"
Statistics:
--
Elements processed: 34
Elements output: 24
Execution time: 0.02 seconds
I looked around, asked a few people but no luck.
I finally found the problem.
There is %
in Log Parser SQL query:
LIKE '2008-%'
%
represents variable in batch file, and if you take a closer look how batch file gets executed you will see that
LIKE '2008-%'
is executed as
LIKE '2008-'
I changed batch file to
LIKE '2008-%%'
and now it works.
tags: code