# [SOLVED] If contains batch file



## Activeradio

I have used the following code in my batch file to detect keywords in a sentence, and go to a section. 

Example:
I can type keywords into Google and get search results. It found 'keyword', so it goes to a section of the file.

Currently, it only detects one keyword, and I want it to detect multiple. I am already using ) ELSE (, but there are some keywords that go to the same section.



Code:


@echo off
echo Would you like to ask a question?
SET /p str= - 
SET found=
FOR %%a IN (%str%) DO IF /i "%%a"=="keyword" SET found=1
IF DEFINED found goto :question
) ELSE ( 
FOR %%a IN (%str%) DO IF /i "%%a"=="keyword1" SET found=1
IF DEFINED found goto :question
) ELSE (
FOR %%a IN (%str%) DO IF /i "%%a"=="keyword2" SET found=1
IF DEFINED found goto :question1


----------



## TheOutcaste

*Re: If contains batch file*

Pipe the response to Findstr using Echo, you can check for multiple keywords


Code:


@Echo off
:_Ask
Echo.Would you like to ask a question?
Set /p str= - 
If "%str%"=="" Goto :EOF
If /I "%str%"=="no" Goto :EOF
Echo.%str%|Findstr /I "keyword keyword1 anotherkeyword"
If %Errorlelevel%==0 Goto Question
Echo.%str%|Findstr /I "keyword2 keyword7"
If %Errorlelevel%==0 Goto Question1
Echo.%str%|Findstr /I "keyword8 keyword10 anotherkeyword17"
If %Errorlelevel%==0 Goto Question2
:: If none of the keywords are found, have them ask another question.
Echo.I can't recognize any of those words, please try again
Goto _Ask


----------



## Activeradio

*Re: If contains batch file*

Your code results in the closing of the window.


----------



## TheOutcaste

*Re: If contains batch file*

Are you double clicking the file to run it instead of running from a Command Prompt?
When running from a Command Prompt, what error do you get?
Does it close before you can enter the keywords, or after entering something? (You did add the *QuestionX* sections to process the keywords, correct?)


----------



## Activeradio

*Re: If contains batch file*

I am double clicking on the bat, which is what my users would do.


----------



## TheOutcaste

*Re: If contains batch file*



TheOutcaste said:


> When running from a Command Prompt, what error do you get?
> Does it close before you can enter the keywords, or after entering something? (You did add the *QuestionX* sections to process the keywords, correct?)


----------



## Activeradio

*Re: If contains batch file*

How do I run your code in command prompt? It still need it to work in a .bat.


----------



## TheOutcaste

*Re: If contains batch file*

If you won't run it in a command prompt it's going to be very hard to troubleshoot. That's the only way to keep the window open to see any error messages.
Click *Start | Run* (or press *WinKey+R*), type *cmd*, press *Enter*
Navigate to the folder with the .bat file, then type it's name.

Spotted a typo that's probably the problem, I ran it on an XP system, then typed it here on my Win 7 system and misspelt Errorlevel as Errorlelevel"

Give this a try:


Code:


@Echo off
:_Ask
Set str=
Echo Would you like to ask a question?
Set /p str= - 
If "%str%"=="" Goto :EOF
If /I "%str%"=="no" Goto :EOF
Echo.%str%|Findstr /I "keyword keyword1 anotherkeyword"
If %Errorlevel%==0 Goto Question
Echo.%str%|Findstr /I "keyword2 keyword7"
If %Errorlevel%==0 Goto Question1
Echo.%str%|Findstr /I "keyword8 keyword10 anotherkeyword17"
If %Errorlevel%==0 Goto Question2
:: If none of the keywords are found, have them ask another question.\
Echo.I can't recognize any of those words, please try again
Goto _Ask


----------



## Activeradio

*Re: If contains batch file*

I have tested the file, and I get this error.



Code:


...is not recognized as an internal or external command,
operable program or batch file


----------



## TheOutcaste

*Re: If contains batch file*

Testing something


----------



## TheOutcaste

*Re: If contains batch file*

Post the complete code you are running, as I have no idea what you've added.

What is the complete error message?
The unrecognized Command will be shown in single quotes, like this:


Code:


'badcommand' is not recognized as an internal or external command,
operable program or batch file.

If it's actually *'...'* then it's part of something you've added, as that isn't present in the above code.

Only error the above code will give is missing label errors, as none of the labels exist.
Also it will find partial matches, so your keywords have to be unique. With the above keywords, *keyword8* will match on the first *If* statement as it contains *keyword*, so the order if the If statements can make a difference, or you may need to specify exact word matches using *\<* and *\>* in the Findstr commands. See Findstr /? for info.


----------



## Activeradio

*Re: If contains batch file*

The ... was the location of the bat, but I fixed the error. I typed in keyword, and I got the following error.



Code:


Goto was unexpected at this time

Source Code


----------



## TheOutcaste

*Re: If contains batch file*

You haven't corrected my typo, you still have error*le*level instead of errorlevel


TheOutcaste said:


> Spotted a typo that's probably the problem, I ran it on an XP system, then typed it here on my Win 7 system and misspelt Errorlevel as Errorlelevel"


Anything you type containing *keyword* will go to question. to use *keyword* and *keyword5* for example, you need to add the word boundries \< and \>:


Code:


Echo %str%|Findstr /I "\<keyword\> \<keyword1\> \<keyword2\>"
If %Errorlevel%==0 Goto question
Echo %str%|Findstr /I "\<keyword3\> \<keyword4\>"
If %Errorlevel%==0 Goto question1
Echo %str%|Findstr /I "\<keyword5\> \<keyword6\> \<keyword7\>"
If %Errorlevel%==0 Goto question2


----------



## Activeradio

*Re: If contains batch file*

Your code seems to be working now. I had quite a few errors in my old code, but this solves it all.

When I type in <, or >, the window closes. I am using if %udefine%==/<, and if %udefine%==/>



Code:


< was unexpected at this time.
The syntax of the command is incorrect




Code:


> was unexpected at this time.
The syntax of the command is incorrect


----------



## TheOutcaste

*Re: If contains batch file*

< and > are redirection symbols, used to redirect console input and output
The are also used by findstr as part of the word boundry Regular expression operators:
*\<* is beginning of word
*\>* is end of word
These characters are not part of the search string, and should not be entered. They just indicate that the match needs to start or end on a word boundary.
Examples:
The user types *wordsmith* or *keyword*:
Echo %str%|Findstr /I "word" will match *wordsmith* and *keyword*
Echo %str%|Findstr /I "\<word" will match *wordsmith* but not *keyword*
Echo %str%|Findstr /I "word\>" will match *keyword* but not *wordsmith*
Echo %str%|Findstr /I "\<word\>" will not match either, it will only match *word*

They can only be used inside the quotes in a search string, or as redirection operators.

If you need to see if the variable udefine has the characters \> you have to quote both operands:
if "%udefine%"=="/<" Echo Found


----------



## Activeradio

*Re: If contains batch file*

I am using if "%udefine%"=="/<" goto :ask, and if "%udefine%"=="/>" goto :ask.



Code:


< was unexpected at this time




Code:


> was unexpected at this time


----------



## TheOutcaste

*Re: If contains batch file*

Using where? Post your code, if they are quoted it shouldn't give that error. Do you have \> or \< someplace else in the file?

You should comment out the Echo off and cls statements so you can debug the code. That what you can see what line is causing the error.
Only put them in when you have all the bugs worked out.
I added if "%udefine%"=="/<" goto :ask for question and it works fine:


Code:


::@Echo off
:ask
::cls
Echo Would you like to ask a question?
Set /p str= - 
If "%str%"=="" Goto :EOF
If /I "%str%"=="no" Goto :EOF
Echo %str%|Findstr /I "keyword keyword1 keyword2"
If %ErrorLevel%==0 Goto question
Echo %str%|Findstr /I "keyword3 keyword4"
If %ErrorLevel%==0 Goto question1
Echo %str%|Findstr /I "keyword5 keyword6 keyword7"
If %ErrorLevel%==0 Goto question2
Goto ask

:question
::cls
echo Question
SET /p udefine= -
[B]If "%udefine%"=="/<" goto :ask
Echo You Entered "%udefine%", exiting[/B]
goto :EOF

:question1
::cls
echo Question 1
SET /p udefine= - 
goto :EOF

:question2
::cls
echo Question 2
SET /p udefine= - 
goto :EOF

and the result (Prompt is blue, text I typed is red:
Trying to add colors in a code box really messes up the spacing, so no box)
==============================

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\TheOutcaste>cd\scripts

C:\Scripts>ask

C:\Scripts>Echo Would you like to ask a question?
Would you like to ask a question?

C:\Scripts>Set /p str= -
- keyword

C:\Scripts>If "keyword" == "" Goto :EOF

C:\Scripts>If /I "keyword" == "no" Goto :EOF

C:\Scripts>Echo keyword | Findstr /I "keyword keyword1 keyword2"
keyword

C:\Scripts>If 0 == 0 Goto question

C:\Scripts>echo Question
Question

C:\Scripts>SET /p udefine= -
-/<

C:\Scripts>If "/<" == "/<" goto :ask

C:\Scripts>Echo Would you like to ask a question?
Would you like to ask a question?

C:\Scripts>Set /p str= -
- keyword

C:\Scripts>If "keyword" == "" Goto :EOF

C:\Scripts>If /I "keyword" == "no" Goto :EOF

C:\Scripts>Echo keyword | Findstr /I "keyword keyword1 keyword2"
keyword

C:\Scripts>If 0 == 0 Goto question

C:\Scripts>echo Question
Question

C:\Scripts>SET /p udefine= -
-/>

C:\Scripts>If "/>" == "/<" goto :ask

C:\Scripts>Echo You Entered "/>", exiting
You Entered "/>", exiting

C:\Scripts>goto :EOF

C:\Scripts>
==============================

If you leave off the quotes you get this, so you can see exactly which line caused the error, the line displayed right after the error:
==============================

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\TheOutcaste>cd\scripts

C:\Scripts>ask

C:\Scripts>Echo Would you like to ask a question?
Would you like to ask a question?

C:\Scripts>Set /p str= -
- keyword

C:\Scripts>If "keyword" == "" Goto :EOF

C:\Scripts>If /I "keyword" == "no" Goto :EOF

C:\Scripts>Echo keyword | Findstr /I "keyword keyword1 keyword2"
keyword

C:\Scripts>If 0 == 0 Goto question

C:\Scripts>echo Question
Question

C:\Scripts>SET /p udefine= -
-/<
*< was unexpected at this time.*

C:\Scripts>*If /< == /< goto :ask
*
C:\Scripts>


----------



## Activeradio

*Re: If contains batch file*

I am not trying to enter "/>", or "/<" into the search box. I am trying to enter <, and >. I was not sure if you understood.

Source Code


----------



## TheOutcaste

*Re: If contains batch file*

I'm not sure what you mean by Search box, unless you mean when the code stops and waits for you to type something.
If you type a &, < or > at the input prompt right after the "Would you like to ask a question?
" prompt, it will give this error:
*| was unexpected at this time.*
This is because the variable in the *Echo %str%|Findstr* command is not quoted. If you need to be able to use those symbols, you need to put quotes around *%str%*

I get no other error running that. Doesn't matter if I enter <, >, \<, \>, /<, or /> at the *question* prompt after entering a keyword.
I'm not sure what you are trying to accomplish. If the user types */<* it will go back to the ASK label and start over, otherwise it exits. I don't see why the user be typing */<* at that point, or the > symbol at all.

There is no way to get to question1 or question2
If they enter keyword3, the first If statement will match on the *keyword* part of keyword3 and they will go to *question*, not *question1*


----------



## Activeradio

*Re: If contains batch file*

I am not sure what is happening, but it works. When I enter a keyword, I get the following error. I used ) ELSE ( between each set keywords because some words need to be priority.



Code:


'}' is not recognized as an internal or external command,
operable program or batch file.


----------



## Activeradio

*Re: If contains batch file*

It seems to only work in the question area, and no where else. It also closes on <, >, and & when they ask a question. Is there any way to avoid this?

Source Code


----------



## TheOutcaste

*Re: If contains batch file*

You've entered a closing brace *}* someplace that is causing that error, perhaps where you meant to have a closing parenthesis.
I don't see a brace or an Else statement in the code you link, but I don't see a reason for an If Else construct for checking the keywords.

The only reason for an Else construct is if you have code you don't want to execute if the preceding IF statement is true, or need to nest the if statement to check multiple values. In this case, it's either found or missing; If found, a goto is executed, so you are already bypassing the next statement; if missing, you want to do the next *echo|Findstr*, there's only one choice, so the Else won't serve a useful purpose.
It will actually slow it down a bit. Using an If - Else structure makes it one line, so even if the first condition is true, the statement after the Else still has to be processed as it's part of the same line. Without the Else, the next statement is a separate line, and is only processed if the first IF is false.

If you need to prioritize words, just put them first.



Activeradio said:


> It also closes on <, >, and & when they ask a question. Is there any way to avoid this?





TheOutcaste said:


> If you need to be able to use those symbols, you need to put quotes around *%str%/B]*


*
This means you have to have quotes around any variable that might contain one of those symbols, not just on the line that checks for them.
(If they enter a single " symbol, it will fail as well. Batch does not handle strings using any of the special characters (!%"^&()<>|) very well)

You can use If /I to do a case insensitive comparison:
All of these need to be quoted:


Code:


if %udefine%==a goto :links
if %udefine%==A goto :links
if %udefine%==b goto :ask
if %udefine%==B goto :ask
if %udefine%==c goto :tools
if %udefine%==C goto :tools

and you only need 3 lines, not 6, like this:


Code:


if /I "%udefine%"=="A" goto :links
if /I "%udefine%"=="B" goto :ask
if /I "%udefine%"=="C" goto :tools

Or, put the check for < and > first, and check for &, then the rest don't need to be quoted.*


----------



## Activeradio

*Re: If contains batch file*

I need to use use } else { because it detects keyword first, and not keyword1.

Example:
Why is keyword better than keyword1? Keyword takes priority because it was said first in the sentence.



Code:


echo %str%|Findstr /I "\<keyword1\>"
if %Errorlevel%==0 Goto :keyword1
echo %str%|Findstr /I "\<keyword\>"
if %Errorlevel%==0 Goto :rsbot
Goto :keyword

I have done "%str%", but it kept closing. It seems to be working now.

Example:
What is TFS (Tech Support Forum) because "I" do not know.

I am not sure what I am suppose to do here. If the user typed the message above, the window should not close. I think you were talking about 1 special character, and no other text?


----------



## TheOutcaste

*Re: If contains batch file*

You can't use *} Else {*, that's not valid. You can only use parentheses to group commands, so it has to be *) Else (*. And don;t forget that have to be in pairs:
If condition (command) Else (command)
That is all one line, even if you place it on 4 or 5 lines in your editor.

I'm assuming you aren't actually going to be using the word Keyword and keyword1, those are just place holders. "keyword keyword1 keyword2" all go to the same place. If you are actually using those words, and they need to go to different places, put *keyword* in the findstr statement that comes after the ones with *keyword1* and *keyword2*.

The point is Findstr searches for the pattern anyplace in the string you have it search _unless_ you specify to only match at the start, or end of a word, or an exact word only.
For example these three questions:

What is TFS (Tech Support Forum) because "I" do not know
How many cites are named Portland.
What does a shipping port do
and these keywords

Support
Portland
port
If *port* is checked first, it will match all three

Sup*port*
*Port*land
*port*
So you have to specify your keywords so that any keyword contained in another (port is contained in Support and Portland) is checked last, or you have to specify word boundaries: *\<port\>* will only match the word *port*, it will not match Support or Portland, so it doesn't matter when it's checked for.

I still don't understand what keywords you'd be looking for at that point. The only logical answer to *Would you like to ask a question?* is *yes* or *no*, there won't be any keywords to look for.

If all you are going to do is pass the question to a search engine, you don't need any of that, you need to parse the question and create a url to use the search engine, for your example question it would be this:


Code:


http://www.google.com/search?&q=What+is+TFS+(Tech+Support+Forum)+because+"I"+do+not+know


----------



## Activeradio

*Re: If contains batch file*

My code will not search though Google. Keyword is a placeholder for the words I am actually going to use. It works the first time, but then it results in this error. Since I have two sets of brackets, the error occurs 2 times. Also, when I type "Google", it skips to one of the results.



Code:


'else' is not recognized as an internal or external command,
operable program or batch file x2

Source Code


----------



## Squashman

*Re: If contains batch file*

What is your phobia with posting your code within code tags on the forums?

Your syntax for the parenthesis is still not correct. Look at TheOutCaste's examples.


----------



## Activeradio

*Re: If contains batch file*

I am still confused on what I am suppose to do. I used ) else ( to remove the error, and it works when I ask a question. If I go back, and ask another question, it redirects to :main.

Source Code


----------



## TheOutcaste

*Re: If contains batch file*

Else is not a separate command. It is part of the If statement, and has to be on the same line. The parentheses serve two purposes, to allow you to continue a single command line on another line _in the editor_ (it's still one line as far as the batch processor is concerned), and to group commands so there is no question about when one ends and another begins. The parentheses *must* be paired.
So you can write a command line two ways. Here's the syntax:

If condition (command) Else (command)
Lets check the value of a variable named *Test*



Code:


Set Test=5
If %test%==5 (Echo Test is 5) Else (Echo Test is not 5)

This can be written like this as well, but note the parentheses are *always* in pairs.

The last set of parentheses aren't need to group the command, the first is so the system knows when the *Echo* command ends. Otherwise *Else* is just seen as part of the text being echoed.


Code:


If %test%==5 (Echo Test is 5) Else Echo Test is not 5

You can split it on separate lines for readability. 



Code:


If %test%==5 (
      Echo Test is 5
   ) Else  (
      Echo Test is not 5
   )

Even though this appears on 5 lines in the editor, it is still only one line as far as the batch processor is concerned; Else has to be on the same "line" as the If statement it is part of.

With the way you've placed the parentheses, you've grouped the *echo|Findstr* line with the following *If* statement, then have *Else* on a separate line, so it's not part of the If statement, so you get an error.
This:


Code:


( echo %str%|Findstr /I "\<keyword\> \<keyword1\> \<keywrd2\>"
if %Errorlevel%==0 Goto :question )
else

Is the same as this:


Code:


echo %str%|Findstr /I "\<keyword\> \<keyword1\> \<keywrd2\>" & if %Errorlevel%==0 Goto :question
else

The parentheses don't really do anything in this case, *else* is still on a different line than the *If* statement


----------



## Activeradio

*Re: If contains batch file*

I think there is something wrong because the window closed, and there is no error.



Code:


if /I "%str%"=="\<keyword1\>"							(
    goto :issue1a
                 ) Else (
if /I "%str%"=="\<keyword2\> \<keywrd3\> \<keyword4\>"		(
    goto :issue1b
                 ) else (
if /I "%str%"=="\<keyword5\> \<keyword6\>"				(
    goto :issue1b
                 )


----------



## TheOutcaste

*Re: If contains batch file*



TheOutcaste said:


> The parentheses *must* be paired.
> ...
> 
> note the parentheses are *always* in pairs.


You have 5 open parentheses, and only 3 closing parentheses.

And again, there is no reason to use Else with this group of statements, it will not change how the commands are processed, except to slow it down.

Without the Else, if the first If statement is true, the Goto is executed, and the next 4 lines won't even be processed.
Using else, all 6 lines become one, so in effect you are forcing it to process all 6 lines when that might not be needed.

Plus the complication of making sure you have the correct number of parentheses, and have them positioned correctly.


----------



## Activeradio

*Re: If contains batch file*

Is there any way to prioritize without using else?


----------



## TheOutcaste

*Re: If contains batch file*

If you have it set to match whole words only, it doesn't matter what order they are in, though obviously the words in the first If statement will be found faster then the ones in the last.
The only reason to "prioritize" is if you are doing a sliding match, and have keywords that are substrings of other keywords. Then, you want to search on the longest words first so the shorter substring doesn't match a longer keyword by mistake.


----------



## Activeradio

*Re: If contains batch file*

Here is the current source code. If the word is not in the list, it will automatically jump to issue1a since that is the first item.

Source Code


----------



## Activeradio

*Re: If contains batch file*

It has been a while since I looked at this. The problem still occurs as I stated above. It is going to the first section which is :issue1a.

Since I have else in there, it should detect the sections in the order I put them in. For example:



> I am running Windows XP, and I received Error 1 in your program


Error 1 should be detected, and Windows XP should not.

Source Code


----------



## TheOutcaste

*Re: If contains batch file*

The else statement will do nothing but cause an error. *Else* *must* be on the same line as the If statement, either physically, or by using line continuation:
The else statement is not needed for this though.



Code:


If condition1true action1 else if condition2true action2 else action3

To use line continuation:


Code:


If condition1true (
  action1
) else (
  If condition2true (
    action2
  ) else (
    action3
  )
)

The else statement is not needed though.

You have the *If %Errorlevel%* statement on the same line as the *findstr* statement. *%Errorlevel%* will be expanded before the *findstr* command is executed, so it will always be 0
To put them on the same line you *MUST* use delayed expansion and use *!* instead of *%*

You've added spaces to the search terms, so it will not match on "error 1" or "error 2" or "error 3". Instead it will match on any word starting with "error" or any word ending with 1, 2, or 3. So if you type in *error 157* it will match on error in the first check and go to issue1b.
If you have spaces in what you want *findstr* to match, you must use */C:* so each search term will be used literally, so the space will be part of the search term. You them have to use */R* to indicate it is a regular expression so the word position operators will be recognized, and not as the \< or \> characters.
You must clear the *str* variable before the *set /P*. Otherwise if they just hit enter, the previous value will be used, it will not enter a null string.

Use this:


Code:


Echo Off
SetLocal EnableDelayedExpansion
:ask
cls
Echo Would you like to ask a question?
Set str=
Set /p str= - 
if "%str%"=="<" Goto :main
if "%str%"==">" Goto :ask
if "%str%"=="" Goto :eof
if /I "%str%"=="no" Goto :main
if /I "%str%"=="EXIT" Exit
echo %str%|Findstr /R /I /C:"\<windows xP\>" & if !Errorlevel!==0 Goto :issue1a
echo %str%|Findstr /R /I /C:"\<error 1\>" /C:"\<error 2\>" /C:"\<error 3\>" & if !Errorlevel!==0 Goto :issue1b
echo %str%|Findstr /R /I /C:"\<error 4\>" /C:"\<error 5\>" & if !Errorlevel!==0 Goto :issue1c
Echo. No Match
Goto ask

or this:


Code:


Echo Off
:ask
cls
Echo Would you like to ask a question?
Set str=
Set /p str= - 
if "%str%"=="<" Goto :main
if "%str%"==">" Goto :ask
if "%str%"=="" Goto :eof
if /I "%str%"=="no" Goto :main
if /I "%str%"=="EXIT" Exit
echo %str%|Findstr /R /I /C:"\<windows xP\>"
if %Errorlevel%==0 Goto :issue1a
echo %str%|Findstr /R /I /C:"\<error 1\>" /C:"\<error 2\>" /C:"\<error 3\>"
if %Errorlevel%==0 Goto :issue1b
echo %str%|Findstr /R /I /C:"\<error 4\>" /C:"\<error 5\>"
if %Errorlevel%==0 Goto :issue1c
Echo. No Match
Goto ask


----------



## Activeradio

*Re: If contains batch file*

I tried your code first to see if it worked, and then modified it a bit to how it was before. Both times, I think it brings up the question, but it automatically goes back to :ask. It was too fast for me to see.

Source Code


----------



## TheOutcaste

*Re: If contains batch file*

Please post your code in this thread, not on a 3rd party site. Makes it much easier for everyone to follow.
Surround the code with code tags ([code]Code goes here[/code]); you can type them in, or highlight the code and click the *#* symbol in the Advanced editor (Click *Go Advanced* under the reply window)
Code copied to this thread


Code:


:ask
cls
Echo Would you like to ask a question?
Set /p str= - 
if "%str%"=="<" Goto :main
if "%str%"==">" Goto :ask
if "%str%"=="" Goto :eof
if /I "%str%"=="no" Goto :main
if /I "%str%"=="EXIT" exit
echo %str%|Findstr /I "\<crash\>" & if !Errorlevel!==0 Goto :issue1a
echo %str%|Findstr /I "\<white\> \<black 2\> \<blank\>" & if !Errorlevel!==0 Goto :issue1b
echo %str%|Findstr /I "\<freeze\> \<frooze\>" & if !Errorlevel!==0 Goto :issue1c
echo %str%|Findstr /I "\<play.bat\>" & if !Errorlevel!==0 Goto :play.bat
echo %str%|Findstr /I "\<update\> \<oudated\> \<work\>" & if !Errorlevel!==0 Goto :update
echo %str%|Findstr /I "\<invalid\> \<corrupt\>" & if !Errorlevel!==0 Goto :invalidorcorrupt
echo %str%|Findstr /I "\<rsbot\>" & if !Errorlevel!==0 Goto :rsbot
Echo. No Match
Goto :ask

For troubleshooting, comment out any Echo Off and CLR statements.
Uncomment them when you've finished debugging.
Use *Goto :EOF* instead of *Exit* so the window won't close. You can change it back to *Exit* commands once you have it working

Open a Command Prompt, and run the file from there. That way you can see what the code is doing. 
You also need to post the complete code. I can't tell if you skipped over the suggestions or just didn't post them.



TheOutcaste said:


> If you have spaces in what you want *findstr* to match, you must use */C:* so each search term will be used literally, so the space will be part of the search term. You them have to use */R* to indicate it is a regular expression so the word position operators will be recognized, and not as the \< or \> characters.
> You must clear the *str* variable before the *set /P*. Otherwise if they just hit enter, the previous value will be used, it will not enter a null string.


You changed the *%* to *!*, but you didn't enable delayed expansion.
You are not using the */R* and */C* switches for the search term that has a space (*black 2*). Each search term on that line must use the */C* and must be quoted.
You are not clearing the *str* variable before the *Set /P* statement.
I've indicated lines commented for testing in blue.
Parts I've added to make it work in Red


Code:


[COLOR=Blue][B]::@Echo Off[/B][/COLOR]
[COLOR=Red][B]SetLocal EnableDelayedExpansion[/B][/COLOR]
:ask
[COLOR=Blue][B]::cls[/B][/COLOR]
Echo Would you like to ask a question?
[COLOR=Red][B]Set str=[/B][/COLOR]
Set /p str= - 
if "%str%"=="<" Goto :main
if "%str%"==">" Goto :ask
if "%str%"=="" Goto :eof
if /I "%str%"=="no" Goto :main
[COLOR=Navy][B]if /I "%str%"=="EXIT" Goto :EOF[/B][/COLOR]
[COLOR=Blue][B]::if /I "%str%"=="EXIT" exit[/B][/COLOR]
echo %str%|Findstr /I "\<crash\>" & if !Errorlevel!==0 Goto :issue1a
echo %str%|Findstr /I [COLOR=Red][B]/R /C:"[/B][/COLOR]\<white\>[COLOR=Red][B]" /C:"[/B][/COLOR]\<black 2\>[COLOR=Red][B]" /C:"[/B][/COLOR]\<blank\>[COLOR=Red][B]"[/B][/COLOR] & if !Errorlevel!==0 Goto :issue1b
echo %str%|Findstr /I "\<freeze\> \<frooze\>" & if !Errorlevel!==0 Goto :issue1c
echo %str%|Findstr /I "\<play.bat\>" & if !Errorlevel!==0 Goto :play.bat
echo %str%|Findstr /I "\<update\> \<oudated\> \<work\>" & if !Errorlevel!==0 Goto :update
echo %str%|Findstr /I "\<invalid\> \<corrupt\>" & if !Errorlevel!==0 Goto :invalidorcorrupt
echo %str%|Findstr /I "\<rsbot\>" & if !Errorlevel!==0 Goto :rsbot
Echo. No Match
Goto :ask
:: Added the following for testing to make sure it [COLOR=Navy][B]jumps to the correct label
:issue1a
@Echo.Jumped to issue1a
Goto ask
:issue1b
@Echo.Jumped to issue1b
Goto ask
:issue1c
@Echo.Jumped to issue1c
Goto ask
:play.bat
@Echo.Jumped to play.bat
Goto ask
:update
@Echo.Jumped to update
Goto ask
:invalidorcorrupt
@Echo.Jumped to invalidorcorrupt
Goto ask
:rsbot
@Echo.Jumped to rsbot
Goto ask
:main
Echo.Main
Goto ask[/B][/COLOR]


----------



## Activeradio

I believe we finally solved the problem. Thanks for your help.


----------

