标题: [文件操作] 批处理输入特殊字符goto异常问题出在哪里? [打印本页]
作者: 流沙染指青春 时间: 2018-11-17 10:47 标题: 批处理输入特殊字符goto异常问题出在哪里?
新人报到,请各位大神多指教问题出在哪里- @echo off
- :MENU
- cls
- color 0a
- set Status=
- type C:\Users\asus\Desktop\Ontune_Check.txt | findstr "陈宝宝" > null && set Status=Ontune Sms Is Open || set Status=Ontune Sms Is Stop
- echo. %Status%
- echo.=-=-=-=-=-Action Options-=-=-=-=-=
- echo.+ +
- echo.+ 1. Ontune Sms Start +
- echo.+ +
- echo.+ 2. Ontune Sms Stop +
- echo.+ +
- echo.+ 3. Exit +
- echo.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==
- echo.
- set /p id=Please Enter Options:
- if "%id%"=="1" ( goto START ) else ( if "%id%"=="2" ( goto STOP ) else ( if "%id%"=="3" ( goto EXIT ) else (if "%id%" == "0" (echo You entered the wrong option please re-enter!!! & pause > null & goto MENU) else (if "%id%" gtr "4" (echo You entered the wrong option please re-enter!!! & pause> null & goto MENU) else (if "%id%" equ "" (echo You entered the wrong option please re-enter!!! & pause > null & goto MENU))))))
- :START
- copy C:\Users\asus\Desktop\Ontune_Check1.txt C:\Users\asus\Desktop\Ontune_Check.txt
- net stop QQMicroGameBoxService
- net start QQMicroGameBoxService
- echo.=-=-=-=-==-=-==-==-=-=-=-=-=-=
- echo. Ontune Sms Is Open
- echo.=-=-=-=-==-=-==-==-=-=-=-=-=-=
- echo Press any key to exit & pause > null
- exit
- :STOP
- copy C:\Users\asus\Desktop\Ontune_Check2.txt C:\Users\asus\Desktop\Ontune_Check.txt
- net stop QQMicroGameBoxService
- net start QQMicroGameBoxService
- echo.=-=-=-=-==-=-==-==-=-=-=-=-=-=
- echo. Ontune Sms Is Stop
- echo.=-=-=-=-==-=-==-==-=-=-=-=-=-=
- echo Press any key to exit & pause > null
- exit
- :EXIT
- exit
复制代码
上面测试内容,当输入特殊的字符特殊符号如“*”、“.”、“/”等,都会自动goto :START,请大神们指正下,小白不胜感激!!!
作者: yhcfsr 时间: 2018-11-17 11:07
本帖最后由 yhcfsr 于 2018-11-17 11:14 编辑
- 现在的小白怎么这么厉害了,真是可怕。下面我胡说八道几句。
- 1.所有的SET语句(含SET /P),都要加双引号;所有路径都要加双引号;虽然这个脚本您不加也没错.
- 2.条件分支,既然都是goto,完全没必要用ELSE,可以这样,整洁明了:
- if xxx goto yyy
- if aaa goto bbb
- ...............
复制代码
- 3.EXIT标签,完全没有存在的必要,直接EXIT不更好?GOTO也是需要时间的,虽然这里可以忽略不计,但养成好的习惯,用最高效的算法对以后处理大数据很重要.
- 4.代码要放在代码框里
作者: lifei259 时间: 2018-11-18 09:17
本帖最后由 lifei259 于 2018-11-18 09:23 编辑
- @echo off&color 0a
- :MENU
- set Status=
- set "check=C:\Users\asus\Desktop\Ontune_Check.txt"
- type %check% | findstr "陈宝宝" > nul && set Status=Ontune Sms Is Open || set Status=Ontune Sms Is Stop
- echo. %Status%
- echo.=-=-=-=-=-Action Options-=-=-=-=-=
- echo.+ +
- echo.+ 1. Ontune Sms Start +
- echo.+ +
- echo.+ 2. Ontune Sms Stop +
- echo.+ +
- echo.+ 3. Exit +
- echo.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==
- echo.
- set /p id=Please Enter Options:
- if "%id%"=="1" goto START
- if "%id%"=="2" goto STOP
- if "%id%"=="3" EXIT
- echo,You entered the wrong option please re-enter!!! & pause > nul
- cls&goto MENU
- :START
- copy /y C:\Users\asus\Desktop\Ontune_Check1.txt %check%
- net stop QQMicroGameBoxService
- net start QQMicroGameBoxService
- echo.=-=-=-=-==-=-==-==-=-=-=-=-=-=
- echo. Ontune Sms Is Open
- echo.=-=-=-=-==-=-==-==-=-=-=-=-=-=
- echo Press any key to exit & pause > nul
- exit
- :STOP
- copy /y C:\Users\asus\Desktop\Ontune_Check2.txt %check%
- net stop QQMicroGameBoxService
- net start QQMicroGameBoxService
- echo.=-=-=-=-==-=-==-==-=-=-=-=-=-=
- echo. Ontune Sms Is Stop
- echo.=-=-=-=-==-=-==-==-=-=-=-=-=-=
- echo Press any key to exit & pause > nul
- exit
复制代码
作者: 流沙染指青春 时间: 2018-11-18 13:17
回复 3# lifei259
好的,谢谢大神指正!
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |