[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] 批处理报错“不是内部或外部命令,也不是可运行的程序或批处理文件”是什么原因

这是源命令
  1. @echo on
  2. :start
  3. echo =====POWER TOOL=====
  4. echo  To restart press 1
  5. echo  To logoff press 2
  6. echo  To shutdown press 3
  7. echo  To exit me press any other key
  8. set NUM=
  9. set /p NUM=Press the key you choose:
  10. %errorlevel%
  11. if "%NUM%"=="1" (
  12. shutdown -r
  13. )
  14. if "%NUM%"=="2" (
  15. logoff
  16. )
  17. if "%NUM%"=="3" (
  18. shutdown -s
  19. )
  20. %errorlevel%
  21. pause
  22. call :start
  23. pause
复制代码
这是运行后的图片
还有就是输入了1,为什么返回的是“1不是………………”这个信息?(不过shutdown命令依旧在我输入1后被执行了
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2
Cease to struggle and you cease to live.

是第20行代码

TOP

回复 2# DAIC
20行不是程序返回码吗?图中为什么会显示“0不是……”,这意思是返回码被当作外部文本被输入了?
还有前面输入1,既然它显示“1不是……”,那为什么实际运行的时候shutdown命令还是被执行了?
Cease to struggle and you cease to live.

TOP

回复 3# Lornan


    批处理是以"关键字+分割符+参数表"的方式来解析每行代码的,你这里面出错的两行就是少了关键字这么一个重要元素,所以它将第一个出现的值作为关键字来解析,也就是说将1和0当成一个命令来看,显然,系统中没有这样的命令,所以提示错误,如果想单纯显示该值,请加相应关键字和分割符,比如
  1. echo,%errorlevel%
复制代码
1

评分人数

    • Lornan: 解释彻底清晰技术 + 1

TOP

回复 3# Lornan


    查看返回码应该是 echo %errorlevel%

TOP

回复 4# amwfjhh


    恩恩,突然想起来了,谢谢
Cease to struggle and you cease to live.

TOP

回复 5# DAIC


    嗯,对,谢谢
Cease to struggle and you cease to live.

TOP

那这个if else语句哪有错?为什么执行了if又执行了else的?
Cease to struggle and you cease to live.

TOP

回复 8# Lornan
  1. @echo off
  2. :start
  3. echo =====POWER TOOL=====
  4. echo  To restart press 1
  5. echo  To logoff press 2
  6. echo  To shutdown press 3
  7. echo  To exit me press any other key
  8. set NUM=
  9. set /p NUM=Press the key you choose:
  10. echo %errorlevel%
  11. if "%NUM%"=="1" (
  12.     shutdown -r
  13. ) else if "%NUM%"=="2" (
  14.     logoff
  15. ) else if "%NUM%"=="3" (
  16.     shutdown -s
  17. )
  18. echo %errorlevel%
  19. pause
  20. goto :start
  21. pause
复制代码
1

评分人数

TOP

回复 9# DAIC


    喔喔,懂了,我的else是当NUM不等于3时就被执行的。而不是不等于1,2,3时才被执行的,要想在不等于1,2,3中任意一个时就echo的话,必须在每一个if语句后都加上相应的else语句 ,一个else只对当前一个if有效,对吧?
Cease to struggle and you cease to live.

TOP

返回列表