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

[其他] 自制命令行没问题,把它改成解释器就不能用了

我做了一个升级版的命令行,代码如下:
  1. @echo off
  2. rem time
  3. set "t=%time%"
  4. rem code
  5. rem time
  6. set "tx=%time%"
  7. rem code
  8. for /f "delims=; tokens=1" %%o in (%cd%\config.ldt) do set conls=%%o
  9. for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
  10. for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
  11. for /f "delims=; tokens=2" %%i in (%cd%\config.ldt) do set dbg=%%i
  12. for /f "delims=; tokens=3" %%t in (%cd%\config.ldt) do set dk=%%t
  13. for /f "delims=; tokens=4" %%b in (%cd%\config.ldt) do set color=%%b
  14. if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
  15. if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
  16. for %%i in (01,02,03,04,05,06,07,08,09,0a,0b,0c,0d,0e,0f,10,12,16,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,21,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,34,35,36,37,38,39,3a,3b,3c,3d,3e,3f,40,41,42,43,45,46,47,48,49,4a,4b,4c,4d,4e,4f50,51,52,53,54,56,57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63,64,65,67,68,69,6a,6b,6c,6d,6e,6f,70,71,72,73,74,75,76,77,78,79,7a,7b,7c,7d,7e,7f,80,81,82,83,84,85,86,87,89,8a,8b,8c,8d,8e,8f,90,91,92,93,94,95,96,97,98,9a,9b,9c,9d,9e,9f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,ab,ac,ab,ac,ad,ae,af,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bc,bd,be,bf,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cd,ce,cf,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,da,db,dc,de,df,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,ea,eb,ec,ed,ef,f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe) do if %color% equ %%i goto colok
  17. goto configerr
  18. :colok
  19. rem time
  20. set "t1x=%time%"
  21. if "%t1x:~,2%" lss "%tx:~,2%" set "add=+24"
  22. set /a "timesx=(%t1x:~,2%-%tx:~,2%%add%)*360000+(1%t1x:~3,2%%%100-1%tx:~3,2%%%100)*6000+(1%t1x:~6,2%%%100-1%tx:~6,2%%%100)*100+(1%t1x:~-2%%%100-1%tx:~-2%%%100)" ,"ssx=(timesx/100)%%60","mmx=(timesx/6000)%%60","hhx=timesx/360000","msx=timesx%%100"
  23. rem endtime
  24. if %dkif% equ b goto nodk
  25. rem time
  26. set "tn=%time%"
  27. rem code
  28. for /f "delims=" %%a in (%cd%\doskey.ldt) do doskey %%a
  29. rem time
  30. set "t1n=%time%"
  31. if "%t1n:~,2%" lss "%tn:~,2%" set "add=+24"
  32. set /a "timesn=(%t1n:~,2%-%tn:~,2%%add%)*360000+(1%t1n:~3,2%%%100-1%tn:~3,2%%%100)*6000+(1%t1n:~6,2%%%100-1%tn:~6,2%%%100)*100+(1%t1n:~-2%%%100-1%tn:~-2%%%100)" ,"ssn=(timesn/100)%%60","mmn=(timesn/6000)%%60","hhn=timesn/360000","msn=timesn%%100"
  33. :nodk
  34. rem time
  35. set "t1=%time%"
  36. if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
  37. set /a "times=(%t1:~,2%-%t:~,2%%add%)*360000+(1%t1:~3,2%%%100-1%t:~3,2%%%100)*6000+(1%t1:~6,2%%%100-1%t:~6,2%%%100)*100+(1%t1:~-2%%%100-1%t:~-2%%%100)" ,"ss=(times/100)%%60","mm=(times/6000)%%60","hh=times/360000","ms=times%%100"
  38. color %color%
  39. mode con cols=%modc% lines=%modl%
  40. if %dbgx% equ a goto dbg
  41. echo 加载文件:
  42. echo 加载配置文件...
  43. echo 完成 用时%hhx%:%mmx%:%ssx%.%msx%(时:分:秒.毫秒)
  44. echo 加载宏命令...
  45. echo 完成 用时%hhn%:%mmn%:%ssn%.%msn%(时:分:秒.毫秒)
  46. echo 加载完成 总用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
  47. echo.
  48. echo BetterCommand Development version 0.1a
  49. echo.
  50. :inputloop
  51. set /p com=^>
  52. if "%com%" equ help %cd%\help.txt
  53. if "%com%" equ exit exit
  54. if "%com%" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  55. if "%shutyn%" equ y shutdown /s /t 0 /f)
  56. %com%
  57. goto inputloop
  58. :configerr
  59. echo 配置文件可能存在问题,加载失败,请检查config.ldt。
  60. pause
  61. exit
  62. :dbg
  63. @echo on
  64. :inputloopdbg
  65. set /p com=^>
  66. if "%com%" equ help %cd%\help.txt
  67. if "%com%" equ exit exit
  68. if "%com%" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  69. if "%shutyn%" equ y shutdown /s /t 0 /f)
  70. %com%
  71. pause
  72. goto inputloopdbg
复制代码
doskey.ldt和config.ldt这两个需要放在和主文件同一个目录下,其中doskey.ldt的内容就是一行行的代号=执行的命令,语法就是doskey命令不打出来开头的doskey几个字。config.ldt内容是:
  1. 窗口大小的列数'行数;是否启用debug模式(false或者true,打开这个模式后回显会开启,并且会执行一条命令暂停一次,让你按任意键继续);是否启用doskey宏功能,关掉它则doskey.ldt的内容不会被加载(false或者true);颜色代码(就是color命令的语法不打出来开头的color几个字)
复制代码
一个帖子有字数限制,另一部分发到二楼。
一个六年级小学生,请多指教

现在做了一个解释器,逐行获取文本里的内容并执行,使用call命令来调用它并传递两个参数,第一个参数是文件的路径(不包含文件本身名称),第二个参数是目标文件的名称,它还会读取文件路径下的config.ldt和doskey.ldt,其中config.ldt内容最后多了一个分号,后面跟着一个选项是用来决定是否显示加载中的文字和加载时间的,如果它为true,那么加载中提示和加载时间显示将会被关闭。现在它不能正常运行,会闪退,麻烦大家再帮我看看,代码如下:
  1. @echo off
  2. SetLocal EnableDelayedExpansion
  3. for /f "delims=; tokens=5" %%q in (%1\config.ldt) do if %%q equ true goto noecho
  4. rem time
  5. set "t=%time%"
  6. rem code
  7. rem time
  8. set "tx=%time%"
  9. rem code
  10. for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
  11. for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
  12. for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
  13. for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
  14. for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
  15. for /f "delims=; tokens=4" %%b in (%1\config.ldt) do set color=%%b
  16. if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
  17. if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
  18. for %%i in (01,02,03,04,05,06,07,08,09,0a,0b,0c,0d,0e,0f,10,12,16,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,21,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,34,35,36,37,38,39,3a,3b,3c,3d,3e,3f,40,41,42,43,45,46,47,48,49,4a,4b,4c,4d,4e,4f50,51,52,53,54,56,57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63,64,65,67,68,69,6a,6b,6c,6d,6e,6f,70,71,72,73,74,75,76,77,78,79,7a,7b,7c,7d,7e,7f,80,81,82,83,84,85,86,87,89,8a,8b,8c,8d,8e,8f,90,91,92,93,94,95,96,97,98,9a,9b,9c,9d,9e,9f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,ab,ac,ab,ac,ad,ae,af,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bc,bd,be,bf,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cd,ce,cf,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,da,db,dc,de,df,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,ea,eb,ec,ed,ef,f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe) do if %color% equ %%i goto colok
  19. goto configerr
  20. :colok
  21. rem time
  22. set "t1x=%time%"
  23. if "%t1x:~,2%" lss "%tx:~,2%" set "add=+24"
  24. set /a "timesx=(%t1x:~,2%-%tx:~,2%%add%)*360000+(1%t1x:~3,2%%%100-1%tx:~3,2%%%100)*6000+(1%t1x:~6,2%%%100-1%tx:~6,2%%%100)*100+(1%t1x:~-2%%%100-1%tx:~-2%%%100)" ,"ssx=(timesx/100)%%60","mmx=(timesx/6000)%%60","hhx=timesx/360000","msx=timesx%%100"
  25. rem endtime
  26. if %dkif% equ b goto nodk
  27. rem time
  28. set "tn=%time%"
  29. rem code
  30. for /f "delims=" %%a in (%cd%\doskey.ldt) do doskey %%a
  31. rem time
  32. set "t1n=%time%"
  33. if "%t1n:~,2%" lss "%tn:~,2%" set "add=+24"
  34. set /a "timesn=(%t1n:~,2%-%tn:~,2%%add%)*360000+(1%t1n:~3,2%%%100-1%tn:~3,2%%%100)*6000+(1%t1n:~6,2%%%100-1%tn:~6,2%%%100)*100+(1%t1n:~-2%%%100-1%tn:~-2%%%100)" ,"ssn=(timesn/100)%%60","mmn=(timesn/6000)%%60","hhn=timesn/360000","msn=timesn%%100"
  35. :nodk
  36. rem time
  37. set "t1=%time%"
  38. if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
  39. set /a "times=(%t1:~,2%-%t:~,2%%add%)*360000+(1%t1:~3,2%%%100-1%t:~3,2%%%100)*6000+(1%t1:~6,2%%%100-1%t:~6,2%%%100)*100+(1%t1:~-2%%%100-1%t:~-2%%%100)" ,"ss=(times/100)%%60","mm=(times/6000)%%60","hh=times/360000","ms=times%%100"
  40. color %color%
  41. mode con cols=%modc% lines=%modl%
  42. if %dbgx% equ a goto dbg
  43. echo 加载文件:
  44. echo 加载配置文件...
  45. echo 完成 用时%hhx%:%mmx%:%ssx%.%msx%(时:分:秒.毫秒)
  46. echo 加载宏命令...
  47. echo 完成 用时%hhn%:%mmn%:%ssn%.%msn%(时:分:秒.毫秒)
  48. echo 加载完成 总用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
  49. echo.
  50. echo BetterCommand Interpreter development version 0.1a
  51. echo.
  52. for /f "delims=" %%r in (%1\%2) do (set /p !com!=<%1\%2
  53. if "!com!" equ help %cd%\help.txt
  54. if "!com!" equ exit exit
  55. if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  56. if "!shutyn!" equ y shutdown /s /t 0 /f)
  57. !com!)
  58. exit
  59. :configerr
  60. echo 配置文件可能存在问题,加载失败,请检查config.ldt。
  61. pause
  62. exit
  63. :dbg
  64. @echo on
  65. for /f "delims=" %%w in (%1\%2) do (set /p com=<%1\%2
  66. if "!com!" equ help %cd%\help.txt
  67. if "!com!" equ exit exit
  68. if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  69. if "!shutyn!" equ y shutdown /s /t 0 /f)
  70. !com!)
  71. exit
  72. exit
  73. pause
  74. :noecho
  75. for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
  76. for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
  77. for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
  78. for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
  79. for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
  80. for /f "delims=; tokens=4" %%b in (%1\config.ldt) do set color=%%b
  81. if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
  82. if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
  83. for %%i in (01,02,03,04,05,06,07,08,09,0a,0b,0c,0d,0e,0f,10,12,16,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,21,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,34,35,36,37,38,39,3a,3b,3c,3d,3e,3f,40,41,42,43,45,46,47,48,49,4a,4b,4c,4d,4e,4f50,51,52,53,54,56,57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63,64,65,67,68,69,6a,6b,6c,6d,6e,6f,70,71,72,73,74,75,76,77,78,79,7a,7b,7c,7d,7e,7f,80,81,82,83,84,85,86,87,89,8a,8b,8c,8d,8e,8f,90,91,92,93,94,95,96,97,98,9a,9b,9c,9d,9e,9f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,ab,ac,ab,ac,ad,ae,af,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bc,bd,be,bf,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cd,ce,cf,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,da,db,dc,de,df,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,ea,eb,ec,ed,ef,f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe) do if %color% equ %%i goto colok
  84. goto configerr
  85. :colokn
  86. if %dkif% equ b goto nodk
  87. for /f "delims=" %%a in (%1\doskey.ldt) do doskey %%a
  88. :nodkn
  89. for /f "delims=" %%y in (%1\%2) do (set /p com=<%1\%2
  90. if "!com!" equ help %cd%\help.txt
  91. if "!com!" equ exit exit
  92. if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  93. if "!shutyn!" equ y shutdown /s /t 0 /f)
  94. !com!)
  95. exit
  96. :configerrn
  97. echo 配置文件可能存在问题,加载失败,请检查config.ldt。
  98. pause
  99. exit
  100. :dbgn
  101. @echo on
  102. for /f "delims=" %%u in (%1\%2) do (set /p com=<%1\%2
  103. if "!com!" equ help %1\%2
  104. if "!com1" equ exit exit
  105. if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  106. if "!shutyn!" equ y shutdown /s /t 0 /f)
  107. !com!
  108. pause)
  109. exit
复制代码
一个六年级小学生,请多指教

TOP

回复 2# LTSC1809


每行代码下面加一行:
pause
观察一下是在第几行代码“闪退”的?
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 3# Batcher


    58行有个exit,所以退出了。但是去掉exit,则会直接显示配置文件存在问题。配置文件存在问题那个是59行的:configerr 那个标签。按理说会执行循环体,然后执行完循环体也就是文本的每一行都执行完了,就会碰到exit退出,但明明那个exit前面是一个for循环,循环提取文件每行内容并执行,为什么会不执行循环而是直接跑到后面的exit呢
一个六年级小学生,请多指教

TOP

回复 3# Batcher

这是我通过call命令运行这个闪退的文件并且后面加上>1.txt 产生的“日志文件”,回显我开了,所以它记录了脚本退出前执行过的每一条命令,可以参考一下:
  1. C:\Users\Administrator>SetLocal EnableDelayedExpansion
  2. C:\Users\Administrator>for /F "delims=; tokens=5" %q in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do if %q EQU true goto noecho
  3. C:\Users\Administrator>if true EQU true goto noecho
  4. C:\Users\Administrator>for /F "delims=; tokens=1" %o in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do set conls=%o
  5. C:\Users\Administrator>set conls=100'30
  6. C:\Users\Administrator>for /F "delims=' tokens=1" %z in ("100'30") do set modc=%z
  7. C:\Users\Administrator>set modc=100
  8. C:\Users\Administrator>for /F "delims=' tokens=2" %e in ("100'30") do set modl=%e
  9. C:\Users\Administrator>set modl=30
  10. C:\Users\Administrator>for /F "delims=; tokens=2" %i in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do set dbg=%i
  11. C:\Users\Administrator>set dbg=false
  12. C:\Users\Administrator>for /F "delims=; tokens=3" %t in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do set dk=%t
  13. C:\Users\Administrator>set dk=true
  14. C:\Users\Administrator>for /F "delims=; tokens=4" %b in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do set color=%b
  15. C:\Users\Administrator>set color=0a
  16. C:\Users\Administrator>if false EQU true (set dbgx=a )  else (if false EQU false (set dbgx=b )  else (goto configerr ) )
  17. C:\Users\Administrator>if true EQU true (set dkif=a )  else (if true EQU false (set dkif=b )  else (goto configerr ) )
  18. C:\Users\Administrator>for %i in (01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 12 16 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 45 46 47 48 49 4a 4b 4c 4d 4e 4f50 51 52 53 54 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 ab ac ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc de df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe) do if 0a EQU %i goto colok
  19. C:\Users\Administrator>if 0a EQU 01 goto colok
  20. C:\Users\Administrator>if 0a EQU 02 goto colok
  21. C:\Users\Administrator>if 0a EQU 03 goto colok
  22. C:\Users\Administrator>if 0a EQU 04 goto colok
  23. C:\Users\Administrator>if 0a EQU 05 goto colok
  24. C:\Users\Administrator>if 0a EQU 06 goto colok
  25. C:\Users\Administrator>if 0a EQU 07 goto colok
  26. C:\Users\Administrator>if 0a EQU 08 goto colok
  27. C:\Users\Administrator>if 0a EQU 09 goto colok
  28. C:\Users\Administrator>if 0a EQU 0a goto colok
  29. C:\Users\Administrator>rem time
  30. C:\Users\Administrator>set "t1x=17:59:56.20"
  31. C:\Users\Administrator>if "17" LSS "~,2" set "add=+24"
  32. C:\Users\Administrator>set /a "timesx=(17-~,2%addt1x:~3,2%C:\Users\Administrator\Desktop\bcitest00-1~3,2%C:\Users\Administrator\Desktop\bcitest00)*6000+(156%100-1~6,2%C:\Users\Administrator\Desktop\bcitest00)*100+(120%100-1~-2%C:\Users\Administrator\Desktop\bcitest00)" ,"ssx=(timesx/100)%60","mmx=(timesx/6000)%60","hhx=timesx/360000","msx=timesx%100"
  33. C:\Users\Administrator>rem endtime
  34. C:\Users\Administrator>if a EQU b goto nodk
  35. C:\Users\Administrator>rem time
  36. C:\Users\Administrator>set "tn=17:59:56.20"
  37. C:\Users\Administrator>rem code
  38. C:\Users\Administrator>for /F "delims=" %a in (C:\Users\Administrator\doskey.ldt) do doskey %a
  39. C:\Users\Administrator>rem time
  40. C:\Users\Administrator>set "t1n=17:59:56.20"
  41. C:\Users\Administrator>if "17" LSS "17" set "add=+24"
  42. C:\Users\Administrator>set /a "timesn=(17-17)*360000+(159%100-159%100)*6000+(156%100-156%100)*100+(120%100-120%100)" ,"ssn=(timesn/100)%60","mmn=(timesn/6000)%60","hhn=timesn/360000","msn=timesn%100"
  43. C:\Users\Administrator>rem time
  44. C:\Users\Administrator>set "t1=17:59:56.21"
  45. C:\Users\Administrator>if "17" LSS "~,2" set "add=+24"
  46. C:\Users\Administrator>set /a "times=(17-~,2%addt1:~3,2%C:\Users\Administrator\Desktop\bcitest00-1~3,2%C:\Users\Administrator\Desktop\bcitest00)*6000+(156%100-1~6,2%C:\Users\Administrator\Desktop\bcitest00)*100+(121%100-1~-2%C:\Users\Administrator\Desktop\bcitest00)" ,"ss=(times/100)%60","mm=(times/6000)%60","hh=times/360000","ms=times%100"
  47. C:\Users\Administrator>color 0a
  48. C:\Users\Administrator>mode con cols=100 lines=30
  49. C:\Users\Administrator>if b EQU a goto dbg
  50. C:\Users\Administrator>echo 加载文件:
  51. 加载文件:
  52. C:\Users\Administrator>echo 加载配置文件...
  53. 加载配置文件...
  54. C:\Users\Administrator>echo 完成 用时::.(时:分:秒.毫秒)
  55. 完成 用时::.(时:分:秒.毫秒)
  56. C:\Users\Administrator>echo 加载宏命令...
  57. 加载宏命令...
  58. C:\Users\Administrator>echo 完成 用时0:0:0.0(时:分:秒.毫秒)
  59. 完成 用时0:0:0.0(时:分:秒.毫秒)
  60. C:\Users\Administrator>echo 加载完成 总用时::.(时:分:秒.毫秒)
  61. 加载完成 总用时::.(时:分:秒.毫秒)
  62. C:\Users\Administrator>echo.
  63. C:\Users\Administrator>echo BetterCommand Interpreter development version 0.1a
  64. BetterCommand Interpreter development version 0.1a
  65. C:\Users\Administrator>echo.
  66. C:\Users\Administrator>for /F "delims=" %r in (C:\Users\Administrator\Desktop\bcitest\114.bat) do (
  67. set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat  
  68. if "!com!" EQU help C:\Users\Administrator\help.txt
  69. if "!com!" EQU exit exit
  70. if "!com!" EQU shutdown (
  71. set /p shutyn=Shutdown now?[Y/N]:  
  72. if "!shutyn!" EQU y shutdown /s /t 0 /f
  73. )  
  74. !com!
  75. )
  76. C:\Users\Administrator>(
  77. set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat  
  78. if "!com!" EQU help C:\Users\Administrator\help.txt
  79. if "!com!" EQU exit exit
  80. if "!com!" EQU shutdown (
  81. set /p shutyn=Shutdown now?[Y/N]:  
  82. if "!shutyn!" EQU y shutdown /s /t 0 /f
  83. )  
  84. !com!
  85. )
  86. C:\Users\Administrator>(
  87. set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat  
  88. if "!com!" EQU help C:\Users\Administrator\help.txt
  89. if "!com!" EQU exit exit
  90. if "!com!" EQU shutdown (
  91. set /p shutyn=Shutdown now?[Y/N]:  
  92. if "!shutyn!" EQU y shutdown /s /t 0 /f
  93. )  
  94. !com!
  95. )
  96. C:\Users\Administrator>(
  97. set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat  
  98. if "!com!" EQU help C:\Users\Administrator\help.txt
  99. if "!com!" EQU exit exit
  100. if "!com!" EQU shutdown (
  101. set /p shutyn=Shutdown now?[Y/N]:  
  102. if "!shutyn!" EQU y shutdown /s /t 0 /f
  103. )  
  104. !com!
  105. )
  106. C:\Users\Administrator>(
  107. set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat  
  108. if "!com!" EQU help C:\Users\Administrator\help.txt
  109. if "!com!" EQU exit exit
  110. if "!com!" EQU shutdown (
  111. set /p shutyn=Shutdown now?[Y/N]:  
  112. if "!shutyn!" EQU y shutdown /s /t 0 /f
  113. )  
  114. !com!
  115. )
  116. C:\Users\Administrator>exit
复制代码
一个六年级小学生,请多指教

TOP

回复 5# LTSC1809


    其中114.bat是我call中附带的参数,它的内容如下:
  1. @echo off
  2. mc
  3. echo a
  4. pause
复制代码
其中的mc这一行是doskey.ldt中定义的语句。它文件夹下的doskey.ldt和config.ldt内容如下,不知道这两个文件有什么用的话可以去看看这个帖子,也是我写的,去看看1楼和23楼,这两层说明了它们的作用:http://www.bathome.net/thread-66697-2-1.html
一个六年级小学生,请多指教

TOP

如果你只是要屏闭输出 直接>nul 不就行了
你好

TOP

回复 5# LTSC1809


    那个set /p 变量=<路径 那里可以看到有个0在<前面,但是我去看了源码,根本没有出现0,我也不知道为啥有个0
一个六年级小学生,请多指教

TOP

回复 7# jyswjjgdwtdtj


    没太看明白你的意思,我并不是要屏蔽什么输出
一个六年级小学生,请多指教

TOP

回复 4# LTSC1809


第一步,把代码里面所有的exit全部改成exit /b
第二步,按照3楼的方法执行代码
第三步,说一下你认为第几行代码执行结果跟你的期望不同
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 LTSC1809 于 2023-7-3 20:16 编辑

回复 11# Batcher


   弄好的代码如下:
  1. @echo off
  2. pause
  3. SetLocal EnableDelayedExpansion
  4. pause
  5. for /f "delims=; tokens=5" %%q in (%1\config.ldt) do if %%q equ true goto noecho
  6. pause
  7. rem time
  8. pause
  9. set "t=%time%"
  10. pause
  11. rem code
  12. pause
  13. rem time
  14. pause
  15. set "tx=%time%"
  16. pause
  17. rem code
  18. pause
  19. for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
  20. pause
  21. for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
  22. pause
  23. for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
  24. pause
  25. for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
  26. pause
  27. for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
  28. pause
  29. for /f "delims=; tokens=4" %%b in (%1\config.ldt) do set color=%%b
  30. pause
  31. if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
  32. pause
  33. if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
  34. pause
  35. for %%i in (01,02,03,04,05,06,07,08,09,0a,0b,0c,0d,0e,0f,10,12,16,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,21,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,34,35,36,37,38,39,3a,3b,3c,3d,3e,3f,40,41,42,43,45,46,47,48,49,4a,4b,4c,4d,4e,4f50,51,52,53,54,56,57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63,64,65,67,68,69,6a,6b,6c,6d,6e,6f,70,71,72,73,74,75,76,77,78,79,7a,7b,7c,7d,7e,7f,80,81,82,83,84,85,86,87,89,8a,8b,8c,8d,8e,8f,90,91,92,93,94,95,96,97,98,9a,9b,9c,9d,9e,9f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,ab,ac,ab,ac,ad,ae,af,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bc,bd,be,bf,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cd,ce,cf,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,da,db,dc,de,df,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,ea,eb,ec,ed,ef,f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe) do if %color% equ %%i goto colok
  36. pause
  37. goto configerr
  38. pause
  39. :colok
  40. pause
  41. rem time
  42. pause
  43. set "t1x=%time%"
  44. pause
  45. if "%t1x:~,2%" lss "%tx:~,2%" set "add=+24"
  46. pause
  47. set /a "timesx=(%t1x:~,2%-%tx:~,2%%add%)*360000+(1%t1x:~3,2%%%100-1%tx:~3,2%%%100)*6000+(1%t1x:~6,2%%%100-1%tx:~6,2%%%100)*100+(1%t1x:~-2%%%100-1%tx:~-2%%%100)" ,"ssx=(timesx/100)%%60","mmx=(timesx/6000)%%60","hhx=timesx/360000","msx=timesx%%100"
  48. pause
  49. rem endtime
  50. pause
  51. if %dkif% equ b goto nodk
  52. pause
  53. rem time
  54. pause
  55. set "tn=%time%"
  56. pause
  57. rem code
  58. pause
  59. for /f "delims=" %%a in (%cd%\doskey.ldt) do doskey %%a
  60. pause
  61. rem time
  62. pause
  63. set "t1n=%time%"
  64. pause
  65. if "%t1n:~,2%" lss "%tn:~,2%" set "add=+24"
  66. pause
  67. set /a "timesn=(%t1n:~,2%-%tn:~,2%%add%)*360000+(1%t1n:~3,2%%%100-1%tn:~3,2%%%100)*6000+(1%t1n:~6,2%%%100-1%tn:~6,2%%%100)*100+(1%t1n:~-2%%%100-1%tn:~-2%%%100)" ,"ssn=(timesn/100)%%60","mmn=(timesn/6000)%%60","hhn=timesn/360000","msn=timesn%%100"
  68. pause
  69. :nodk
  70. pause
  71. rem time
  72. pause
  73. set "t1=%time%"
  74. pause
  75. if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
  76. pause
  77. set /a "times=(%t1:~,2%-%t:~,2%%add%)*360000+(1%t1:~3,2%%%100-1%t:~3,2%%%100)*6000+(1%t1:~6,2%%%100-1%t:~6,2%%%100)*100+(1%t1:~-2%%%100-1%t:~-2%%%100)" ,"ss=(times/100)%%60","mm=(times/6000)%%60","hh=times/360000","ms=times%%100"
  78. pause
  79. color %color%
  80. pause
  81. mode con cols=%modc% lines=%modl%
  82. pause
  83. if %dbgx% equ a goto dbg
  84. pause
  85. echo 加载文件:
  86. pause
  87. echo 加载配置文件...
  88. pause
  89. echo 完成 用时%hhx%:%mmx%:%ssx%.%msx%(时:分:秒.毫秒)
  90. pause
  91. echo 加载宏命令...
  92. pause
  93. echo 完成 用时%hhn%:%mmn%:%ssn%.%msn%(时:分:秒.毫秒)
  94. pause
  95. echo 加载完成 总用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
  96. pause
  97. echo.
  98. pause
  99. echo BetterCommand Interpreter development version 0.1a
  100. pause
  101. echo.
  102. pause
  103. for /f "delims=" %%r in (%1\%2) do (set /p !com!=<%1\%2
  104. pause
  105. if "!com!" equ help %cd%\help.txt
  106. pause
  107. if "!com!" equ exit /b exit /b
  108. pause
  109. if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  110. pause
  111. if "!shutyn!" equ y shutdown /s /t 0 /f)
  112. pause
  113. !com!)
  114. pause
  115. exit /b
  116. pause
  117. :configerr
  118. pause
  119. echo 配置文件可能存在问题,加载失败,请检查config.ldt。
  120. pause
  121. pause
  122. pause
  123. exit /b
  124. pause
  125. :dbg
  126. pause
  127. @echo on
  128. pause
  129. for /f "delims=" %%w in (%1\%2) do (set /p com=<%1\%2
  130. pause
  131. if "!com!" equ help %cd%\help.txt
  132. pause
  133. if "!com!" equ exit /b exit /b
  134. pause
  135. if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  136. pause
  137. if "!shutyn!" equ y shutdown /s /t 0 /f)
  138. pause
  139. !com!)
  140. pause
  141. exit /b
  142. pause
  143. exit /b
  144. pause
  145. pause
  146. pause
  147. :noecho
  148. pause
  149. for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
  150. pause
  151. for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
  152. pause
  153. for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
  154. pause
  155. for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
  156. pause
  157. for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
  158. pause
  159. for /f "delims=; tokens=4" %%b in (%1\config.ldt) do set color=%%b
  160. pause
  161. if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
  162. pause
  163. if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
  164. pause
  165. for %%i in (01,02,03,04,05,06,07,08,09,0a,0b,0c,0d,0e,0f,10,12,16,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f,20,21,23,24,25,26,27,28,29,2a,2b,2c,2d,2e,2f,30,31,32,34,35,36,37,38,39,3a,3b,3c,3d,3e,3f,40,41,42,43,45,46,47,48,49,4a,4b,4c,4d,4e,4f50,51,52,53,54,56,57,58,59,5a,5b,5c,5d,5e,5f,60,61,62,63,64,65,67,68,69,6a,6b,6c,6d,6e,6f,70,71,72,73,74,75,76,77,78,79,7a,7b,7c,7d,7e,7f,80,81,82,83,84,85,86,87,89,8a,8b,8c,8d,8e,8f,90,91,92,93,94,95,96,97,98,9a,9b,9c,9d,9e,9f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,ab,ac,ab,ac,ad,ae,af,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bc,bd,be,bf,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,ca,cb,cd,ce,cf,d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,da,db,dc,de,df,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,ea,eb,ec,ed,ef,f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,fa,fb,fc,fd,fe) do if %color% equ %%i goto colok
  166. pause
  167. goto configerr
  168. pause
  169. :colokn
  170. pause
  171. if %dkif% equ b goto nodk
  172. pause
  173. for /f "delims=" %%a in (%1\doskey.ldt) do doskey %%a
  174. pause
  175. :nodkn
  176. pause
  177. for /f "delims=" %%y in (%1\%2) do (set /p com=<%1\%2
  178. pause
  179. if "!com!" equ help %cd%\help.txt
  180. pause
  181. if "!com!" equ exit /b exit /b
  182. pause
  183. if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  184. pause
  185. if "!shutyn!" equ y shutdown /s /t 0 /f)
  186. pause
  187. !com!)
  188. pause
  189. exit /b
  190. pause
  191. :configerrn
  192. pause
  193. echo 配置文件可能存在问题,加载失败,请检查config.ldt。
  194. pause
  195. pause
  196. pause
  197. exit /b
  198. pause
  199. :dbgn
  200. pause
  201. @echo on
  202. pause
  203. for /f "delims=" %%u in (%1\%2) do (set /p com=<%1\%2
  204. pause
  205. if "!com!" equ help %1\%2
  206. pause
  207. if "!com1" equ exit /b exit /b
  208. pause
  209. if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
  210. pause
  211. if "!shutyn!" equ y shutdown /s /t 0 /f)
  212. pause
  213. !com!
  214. pause
  215. pause)
  216. pause
  217. exit /b
复制代码
发现最后一次输出是:
  1. 系统找不到文件 C:\Users\Administrator\Desktop\bcitest\C:\Users\Administrator\Desktop\bcitest\114.bat
复制代码
路径重复了两次,这是怎么回事啊
一个六年级小学生,请多指教

TOP

回复 12# LTSC1809


    11楼的三步是为了帮你找到代码中的问题,问题解决之后你就怎么高兴怎么改。
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

话说没搞懂你到底要干啥
如果只是读取再运行直接
  1. for /f "delims=" %%i in ('type C:\Users\admin\xx\1.txt') do set b=%%i
  2. %b%
复制代码
不就行了?
你好

TOP

回复 13# jyswjjgdwtdtj


    这...%b%要等for执行完才会执行,所以它的内容是%%i最后一次,也就是文档里最后一行的内容
一个六年级小学生,请多指教

TOP

回复 14# LTSC1809


13楼代码改成这样试试:
  1. for /f "delims=" %%i in ('type 1.txt') do "%%i"
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表