Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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^> )

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

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

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

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.

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 displayedI 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.

![]() |
Zip all files in folder u...
|
Delete header lines and s...
|

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