Compare strings

August 31, 2009 at 18:05:46
Specs: Windows XP
I need to capture the default output from a command-line application. Example of the default output "sample msg 01" If this default message is throw than I want to catch that information and write my own message.

Snippet of the code that calls this application.

for /f "delims=" %%a in ('myApp.exe ^|FIND /V /I "stripInfo01"') do (
echo ^<pre^>^<span style="font-size: 12pt"^>%%a ^</span^>^</pre^> )


See More: Compare strings

Report •


#1
August 31, 2009 at 20:17:10
What exactly does your code not do that you need it to?

Report •

#2
September 1, 2009 at 00:43:35
The code work fine, but I found out during QA testing that the code does not write the result correctly when the data point does not exist in the system log files. The external binary that I am calling does not have a method to disable default messages. When this message is thrown to %%a, I want to compare that string to another string and than write my own message.

I am thinking something like this:

for /f "delims=" %%a in ('myApp.exe ^|FIND /V /I "stripInfo01"') do (

if %%a == "default string"

echo ^<pre^>^<span style="font-size: 12pt"^>"No events found." ^</span^>^</pre^>

else
( // if events exist this will display them.
echo ^<pre^>^<span style="font-size: 12pt"^>%%a ^</span^>^</pre^> ))


Report •

#3
September 1, 2009 at 01:24:04
The if statement is one of the most important in any language,
it's well worth looking up the language specific syntax "if /?"
at the command line...

for /f "delims=" %%a in ('myApp.exe ^|FIND /V /I "stripInfo01"') do (

    if "%%a"=="default string" (
        echo ^<pre^>^<span style="font-size: 12pt"^>"No events found." ^</span^>^</pre^>

    ) else (
        rem if events exist this will display them.
        echo ^<pre^>^<span style="font-size: 12pt"^>%%a ^</span^>^</pre^> 
    )
)


Report •

Related Solutions

#4
September 1, 2009 at 08:05:14
Thanks. After some more testing I found that the string that I need to catch is being displayed on two lines. I determine this by adding some additional code:

echo %%a
message one .
message two \\:
pause
echo %%a
message two \\:
pause
echo %%a
message two \\:
pause


How can I trap "message one ." and message two \\: in the compare function below?

if "%%a"=="message two. message two \\:"


Report •

#5
September 4, 2009 at 08:04:22
Perhaps something like this may help....


setlocal enabledelayedexpansion
<your for loop> do (

    if "%%a"=="default mesage 1" (
        set default=1
    ) else (
        if "!default!"=="1" if "%%a"=="default message2" (
            rem your replacement message
        )
    )
)

You may also have to add your other stuff into an if statement so it doesn't get executed when the default message is output.


Report •

#6
September 16, 2009 at 11:38:33
Sorry for the delayed response, I have been away.

Here are the real strings:

When my query produces results the first string is: Security log on \\:
and then the results are displayed

I want the batch to process the results from this positive query. I would like to strip the string "Security log on \\:" from the output.

When my query produces no results the first string is:
Security log on \\:
and the second string is:
No records in Security event log on .

I would like the batch to capture these strings and display a custom message.


Report •


Ask Question