4

无论该字符串是否包含在 MRSVANDERTRAMP.txt 中,任何放入此批处理文件这一部分的内容都会自动转到 :yes。

:enterverb
set /p id=Enter Verb: 

findstr /m %id% MRSVANDERTRAMP.txt
if %errorlevel%==0 (
goto :yes 
) else (
goto :no
)

:no
echo Verb does not take etre in the Perfect Tense. 
pause
goto :option0

:yes
echo Verb is a MRSVANDERTRAMP verb and takes etre in the Perfect Tense.
pause
4

4 回答 4

1

我想出了一个类似的代码来测试它,它可以工作。

@echo off
@title TEST

:main
set /p word=Write a word: 

findstr /M %word% words.txt

if "%errorlevel%" == "0" ( echo FOUND ) else ( echo NOT FOUND )
pause>nul
cls && goto main




也许 IF 语句有问题..尝试使用

if "%errorlevel%" == "0" 

而不是

if %errorlevel%==0
于 2013-09-10T20:25:30.190 回答
0

大佬试试这个

进入动词

set /p id=Enter Verb: 
findstr /m %id% MRSVANDERTRAMP.txt

set a=0

if %errorlevel%== %a% (
goto :yes 
) else (
goto :no
)

:no
echo Verb does not take etre in the Perfect Tense. 
pause
goto :option0

:yes
echo Verb is a MRSVANDERTRAMP verb and takes etre in the Perfect Tense.
于 2014-11-22T16:56:44.780 回答
0

这工作正常。您可能希望"%id%"如图所示用双引号括起来,以防止某些有毒字符。

@echo off

echo one>MRSVANDERTRAMP.txt
echo two>>MRSVANDERTRAMP.txt


:enterverb
set /p id=Enter Verb: 

findstr /m %id% MRSVANDERTRAMP.txt
if %errorlevel%==0 (
goto :yes 
) else (
goto :no
)

:no
echo Verb does not take etre in the Perfect Tense. 
pause
goto :option0

:yes
echo Verb is a MRSVANDERTRAMP verb and takes etre in the Perfect Tense.
pause

:option0
echo done
pause
于 2013-09-10T22:03:33.840 回答
0

我在这段代码中遇到了同样的问题:

@echo off

ping www.google.com
if %errorlevel%== 0 (
goto :ok
) else (
go to :fail
)

:ok
echo ok
pause

:fail
echo fail
pause

总是去,:okvar=0我的问题解决了,我的代码运行了。

@echo off
ping www.google.com
set a=0
if %errorlevel%== %a% (
goto :ok
) else (
goto :fail
)

:ok
echo ok
pause


:fail
echo fail
pause
于 2014-11-22T17:46:48.267 回答