本帖最后由 LTSC1809 于 2023-7-1 22:42 编辑
它的同目录下有两个后缀为.ldt的文件,config.ldt的内容为- true或者false;true或者false;颜色代码
复制代码 doskey.ldt的内容为复制代码 ,doskey.ldt有好几行,但都是这种格式。这个bat开头会读取它们的内容并用到它们。现在打开以后没有显示出来加载用时,而且没有出现宏命令加载中的文字,还有就是出现输入文字的地方以后输入任何内容回车以后都会闪退,用cmd运行它,发现不管输入什么都显示此处不应有啥啥啥,求解。我自己看半天没看出问题来,代码如下:- @echo off
- echo 加载文件:
- echo 加载配置文件...
- rem time
- set "t=%time%"
- rem code
- setlocal
- rem time
- set "t=%time%"
- rem code
- for /f "delims=; tokens=1" %%i in (%cd%\config.ldt) do set dbg=%%i
- for /f "delims=; tokens=2" %%t in (%cd%\config.ldt) do set dk=%%t
- for /f "delims=; tokens=3" %%b in (%cd%\config.ldt) do set color=%%b
- if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
- if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
- 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
- goto configerr
- rem time
- set "t1=%time%"
- if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
- 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"
- echo 完成 用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
- rem endtime
- if %dkif% equ b=goto nodk
- rem time
- set "t=%time%"
- rem code
- echo 加载宏命令...
- for /f %%a in (%cd%\doskey.ldt) do doskey %%a
- rem time
- set "t1=%time%"
- if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
- 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"
- echo 完成 用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
- endlocal
- :nodk
- rem time
- set "t1=%time%"
- if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
- 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"
- echo 加载完成 总用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
- :colok
- color %color%
- if %dbgx% equ a=goto dbg
- echo.
- echo BetterCommand Development version 0.1a
- echo.
- :inputloop
- set /p com=^>
- if %com% equ help=%cd%\help.txt
- if %com% equ exit=exit
- if %com% equ shutdown (set /p shutyn=Shutdown now?(Y/N):
- if %shutyn% equ y=shutdown /s /t 0 /f)
- %com%
- goto inputloop
- :configerr
- echo 配置文件可能存在问题,加载失败,请检查config.ldt。
- pause
- exit
- :dbg
- @echo on
- :inputloopdbg
- set /p com=^>
- if %com% equ help=%cd%\help.txt
- if %com% equ exit=exit
- if %com% equ shutdown (set /p shutyn=Shutdown now?(Y/N):
- if %shutyn% equ y=shutdown /s /t 0 /f)
- %com%
- pause
- goto inputloopdbg
复制代码
|