[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]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几个字)
复制代码
一个帖子有字数限制,另一部分发到二楼。
一个六年级小学生,请多指教

处理后是配置文件可能存在问题,加载失败,请检查config.ldt。
QQ 1980286392

TOP

我看了是显示"此时不应有'true'"
QQ 1980286392

TOP

可以用terminal运行一下,可以显示错误信息
QQ 1980286392

TOP

回复 17# LTSC1809


    哦 之前没看懂你的意思
你可以exec一个cmd 然后读取bat 输入到cmd里执行
你好

TOP

要不要考虑一下嵌套cmd
QQ 1980286392

TOP

回复 17# LTSC1809


    扔在第一个bat里
你好

TOP

回复 15# Batcher


    我还需要if判断是否是那几个命令,不是的话再直接执行,这怎么办
一个六年级小学生,请多指教

TOP

给你支个招 用vbs 先exec一个cmd窗口 先执行你要用来设定控制台窗口的bat 再执行你要运行bat
你好

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

回复 13# jyswjjgdwtdtj


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

TOP

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

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

本帖最后由 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

回复 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

返回列表