Computing.Net > Forums > Programming > Compare strings

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Compare strings

Reply to Message Icon

Name: needToCode
Date: August 31, 2009 at 18:05:46 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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^> )



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: August 31, 2009 at 20:17:10 Pacific
Reply:

What exactly does your code not do that you need it to?


0

Response Number 2
Name: needToCode
Date: September 1, 2009 at 00:43:35 Pacific
Reply:

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^> ))


0

Response Number 3
Name: Judago
Date: September 1, 2009 at 01:24:04 Pacific
Reply:

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^> 
    )
)


0

Response Number 4
Name: needToCode
Date: September 1, 2009 at 08:05:14 Pacific
Reply:

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 \\:"


0

Response Number 5
Name: Judago
Date: September 4, 2009 at 08:04:22 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: needToCode
Date: September 16, 2009 at 11:38:33 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Zip all files in folder u... Delete header lines and s...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Compare strings

Batch file for comparing strings www.computing.net/answers/programming/batch-file-for-comparing-strings-/17507.html

Comparing strings in folder names www.computing.net/answers/programming/comparing-strings-in-folder-names/15701.html

comparing strings in java www.computing.net/answers/programming/comparing-strings-in-java/4147.html