标题: [其他] 求助,我做了一个升级版的cmd,运行不正常 [打印本页]
作者: LTSC1809 时间: 2023-7-1 22:29 标题: 求助,我做了一个升级版的cmd,运行不正常
本帖最后由 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
复制代码
作者: Batcher 时间: 2023-7-1 22:50
回复 1# LTSC1809
if %color% equ %%i=goto colok
这种格式的if命令你写了很多个,先把等号改成空格试试吧。
作者: LTSC1809 时间: 2023-7-1 22:59
好的,等号是不是容易被当成赋值号啊,刚接触bat学判断输入内容的时候看百度知道说的if就是用等号,营销号真是害人不浅啊,我现在都习惯了等号了,基本只要不是多行命令用括号其他都用的等号[捂脸哭]
作者: Batcher 时间: 2023-7-1 23:09
回复 3# LTSC1809
不知道你看的是哪篇文章,也可能是你理解错了。
作者: LTSC1809 时间: 2023-7-2 00:15
回复 4# Batcher 刚刚看了一下那篇教程,确实是空格欸,我用了这么久的等号竟然不报错能用,堪称奇迹
作者: 77七 时间: 2023-7-2 06:38
回复 5# LTSC1809
等号、逗号、分号、空格、制表符 大概都可以
http://bbs.bathome.net/viewthread.php?tid=2286
这个代码就用的 逗号
作者: 77七 时间: 2023-7-2 07:16
本帖最后由 77七 于 2023-7-2 07:37 编辑
- @echo off
- ::第7行
- setlocal enabledelayedexpansion
- ::第11-15行
- for /f "useback tokens=1-3 delims=;" %%a in ("%cd%\config.ldt") do (
- set color=%%c
- if "%%a" equ "true" (
- set dbgx=a
- ) else if "%%a" equ "false" (
- set dbgx=b
- ) else (
- goto :configerr
- )
- rem ...
- )
- ::第16行
- echo %color%|findstr /rbec:"[0-9a-f][0-9a-f]" |findstr /ivc:"%color:~0,1%%color:~0,1%" 1>nul && (
- goto :colok
- ) || (
- goto :configerr
- )
-
- ::第18-41行,不会被执行
- ::第52-53行
- if "%com%" equ "shutdown" (
- set /p shutyn=Shutdown now?[Y/N]:
- if /i "!shutyn!" equ "y" (
- shutdown /s /t 0 /f
- )
- )
-
- ::后续未修改
-
- ::耗时部分
- set "t=%time%"
- rem ...
- set "t1=%time%"
- call :c
-
- set "t=%time%"
- rem ...
- set "t1=%time%"
- call :c
-
- ::这段放代码 exit 命令之后
- :c
- 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)"
- echo 检索时间 %times% ms
- exit /b
复制代码
根据我的经验和习惯改的,有些地方改的可能不正确。
作者: LTSC1809 时间: 2023-7-2 07:56
回复 7# 77七 感谢!尤其是findstr判断颜色代码是不是正确,比我用for一种一种判断好多了
作者: LTSC1809 时间: 2023-7-2 08:03
我自己发现一个问题,就是有两个变量在加载的时候被赋值,后面要判断它们的内容,但是我限制了变量作用域,这样它们就没办法在后面判断了,加变量作用域是为了计时器,计时器有好几个,变量冲突了,这个计时器是照搬论坛某贴的代码,我不会改变量名啊
作者: LTSC1809 时间: 2023-7-2 08:08
回复 7# 77七
网上看到说bat的if不能else if,要用嵌套形式,即else (if xxx equ xxx exit)这种,真的吗您的代码中好像有else if
作者: Batcher 时间: 2023-7-2 10:04
回复 10# LTSC1809
不能elseif,能else if,有可能是你看的不仔细吧
作者: LTSC1809 时间: 2023-7-2 12:23
我改过的代码,现在还是故障依旧,Batcher说的if 等于号换成空格我改了,还有就是去掉了变量作用域,但是现在还是不显示正在加载宏命令,也不显示加载用时,还有就是一输入命令就闪退,改完的代码如下:- @echo off
- echo 加载文件:
- echo 加载配置文件...
- rem time
- set "t=%time%"
- rem code
- rem time
- set "tx=%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 "t1x=%time%"
- if "%t1x:~,2%" lss "%tx:~,2%" set "add=+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"
- echo 完成 用时%hhx%:%mmx%:%ssx%.%msx%(时:分:秒.毫秒)
- rem endtime
- if %dkif% equ b goto nodk
- rem time
- set "tn=%time%"
- rem code
- echo 加载宏命令...
- for /f %%a in (%cd%\doskey.ldt) do doskey %%a
- rem time
- set "t1n=%time%"
- if "%t1n:~,2%" lss "%tn:~,2%" set "add=+24"
- 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"
- echo 完成 用时%hhn%:%mmn%:%ssn%.%msn%(时:分:秒.毫秒)
- :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
复制代码
作者: 77七 时间: 2023-7-2 13:57
回复 12# LTSC1809
7楼代码if "%com%" equ "shutdown" (
set /p shutyn=Shutdown now?[Y/N]:
if /i "!shutyn!" equ "y" (
shutdown /s /t 0 /f
)
)
不是比较数值大小,就把变量用引号括起来,否则变量为空值就闪退,就像这里的 %shutyn%肯定是空值,必须开启变量延迟扩展,使用 !shutyn!;
在括号内使用set /p 后面不要用(),或者使用 ^ 转义,^( ^),否则闪退。
作者: LTSC1809 时间: 2023-7-2 14:05
回复 13# 77七
谢了!那么,开头的加载时间还有正在加载宏命令这些东西不显示是为什么
作者: 77七 时间: 2023-7-2 14:09
回复 14# LTSC1809
1楼代码第17行,使用 goto 跳转了。(7楼代码第23行)
作者: LTSC1809 时间: 2023-7-2 14:09
还有就是发现宏命令不起作用,有的人说只有在交互式的地方doskey才有用,但是我之前亲测过,只做一个简单的循环用set /p获取输入然后执行,通过set /p输入的指令也能用doskey定义的指令,所以这里也是一样用set /p获取输入,为什么宏命令不起作用
作者: LTSC1809 时间: 2023-7-2 14:11
回复 15# 77七
也就是说宏命令根本没被加载?我说怎么用不了doskey.ldt里定义的内容,但是我的config.ldt写到doskey功能是开了的啊,为什么不行
作者: LTSC1809 时间: 2023-7-2 14:13
回复 15# 77七
不对啊,一楼代码17行是跳转到configerr这个标签,但是跳转了的话应该显示配置文件有问题啊,为什么还是让你输入命令了
作者: 77七 时间: 2023-7-2 14:18
回复 18# LTSC1809
1楼代码16行还存在一个可能的goto 跳转。
作者: LTSC1809 时间: 2023-7-2 14:47
感谢大家的答复,现在已经完全正常了,我还给他加了在配置文件里设置窗口大小的功能,代码如下:- @echo off
- rem time
- set "t=%time%"
- rem code
- rem time
- set "tx=%time%"
- rem code
- for /f "delims=; tokens=1" %%o in (%cd%\config.ldt) do set conls=%%o
- for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
- for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
- for /f "delims=; tokens=2" %%i in (%cd%\config.ldt) do set dbg=%%i
- for /f "delims=; tokens=3" %%t in (%cd%\config.ldt) do set dk=%%t
- for /f "delims=; tokens=4" %%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
- :colok
- rem time
- set "t1x=%time%"
- if "%t1x:~,2%" lss "%tx:~,2%" set "add=+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"
- rem endtime
- if %dkif% equ b goto nodk
- rem time
- set "tn=%time%"
- rem code
- for /f "delims=" %%a in (%cd%\doskey.ldt) do doskey %%a
- rem time
- set "t1n=%time%"
- if "%t1n:~,2%" lss "%tn:~,2%" set "add=+24"
- 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"
- :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"
- color %color%
- mode con cols=%modc% lines=%modl%
- if %dbgx% equ a goto dbg
- echo 加载文件:
- echo 加载配置文件...
- echo 完成 用时%hhx%:%mmx%:%ssx%.%msx%(时:分:秒.毫秒)
- echo 加载宏命令...
- echo 完成 用时%hhn%:%mmn%:%ssn%.%msn%(时:分:秒.毫秒)
- echo 加载完成 总用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
- 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
复制代码
doskey.ldt和config.ldt这两个需要放在和主文件同一个目录下,其中doskey.ldt的内容就是一行行的代号=执行的命令,语法就是doskey命令不打出来开头的doskey几个字。config.ldt内容是:- 窗口大小的列数'行数;是否启用debug模式(false或者true,打开这个模式后回显会开启,并且会执行一条命令暂停一次,让你按任意键继续);是否启用doskey宏功能,关掉它则doskey.ldt的内容不会被加载(false或者true);颜色代码(就是color命令的语法不打出来开头的color几个字)
复制代码
这些文件都有了并且格式正确以后,双击打开bat主文件,就能体验了,最后再次感谢大家的帮助,没有你们我不可能完成这项作品。
作者: 77七 时间: 2023-7-2 15:19
回复 20# LTSC1809
代码还有不少错误,和潜在的问题,请仔细看下7楼。
- @echo off
- ::耗时部分,每次取得前后两个时间,使用call :c
- set "str1=%time%"
- timeout 1
- set "str2=%time%"
- call :c "%str1%" "%str2%"
- pause
-
- :c
- set "t=%~1"
- set "t1=%~2"
- 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)"
- echo 检索时间 %times% ms
- exit /b
复制代码
作者: LTSC1809 时间: 2023-7-2 15:50
回复 21# 77七
不瞒您说,这种百分号里括着引号,波浪号的到底是什么意思啊,我完全看不懂。很多地方都看不懂,就没法按照自己的需求改,所以最后索性放弃了,我还是再去看看教程吧[捂脸哭]
作者: LTSC1809 时间: 2023-7-2 16:05
我现在做了一个解释器,逐行获取文本里的内容并执行,使用call命令来调用它并传递两个参数,第一个参数是文件的路径(不包含文件本身名称),第二个参数是目标文件的名称,它还会读取文件路径下的config.ldt和doskey.ldt,其中config.ldt内容最后多了一个分号,后面跟着一个选项是用来决定是否显示加载中的文字和加载时间的,如果它为true,那么加载中提示和加载时间显示将会被关闭。现在它不能正常运行,会闪退,麻烦大家再帮我看看,代码如下:- @echo off
- SetLocal EnableDelayedExpansion
- for /f "delims=; tokens=5" %%q in (%1\config.ldt) do if %%q equ true goto noecho
- rem time
- set "t=%time%"
- rem code
- rem time
- set "tx=%time%"
- rem code
- for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
- for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
- for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
- for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
- for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
- for /f "delims=; tokens=4" %%b in (%1\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
- :colok
- rem time
- set "t1x=%time%"
- if "%t1x:~,2%" lss "%tx:~,2%" set "add=+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"
- rem endtime
- if %dkif% equ b goto nodk
- rem time
- set "tn=%time%"
- rem code
- for /f "delims=" %%a in (%cd%\doskey.ldt) do doskey %%a
- rem time
- set "t1n=%time%"
- if "%t1n:~,2%" lss "%tn:~,2%" set "add=+24"
- 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"
- :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"
- color %color%
- mode con cols=%modc% lines=%modl%
- if %dbgx% equ a goto dbg
- echo 加载文件:
- echo 加载配置文件...
- echo 完成 用时%hhx%:%mmx%:%ssx%.%msx%(时:分:秒.毫秒)
- echo 加载宏命令...
- echo 完成 用时%hhn%:%mmn%:%ssn%.%msn%(时:分:秒.毫秒)
- echo 加载完成 总用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
- echo.
- echo BetterCommand Interpreter development version 0.1a
- echo.
- for /f "delims=" %%r in (%1\%2) do (set /p !com!=<%1\%2
- 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!)
- exit
- :configerr
- echo 配置文件可能存在问题,加载失败,请检查config.ldt。
- pause
- exit
- :dbg
- @echo on
- for /f "delims=" %%w in (%1\%2) do (set /p com=<%1\%2
- 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!)
- exit
- exit
- pause
- :noecho
- for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
- for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
- for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
- for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
- for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
- for /f "delims=; tokens=4" %%b in (%1\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
- :colokn
- if %dkif% equ b goto nodk
- for /f "delims=" %%a in (%1\doskey.ldt) do doskey %%a
- :nodkn
- for /f "delims=" %%y in (%1\%2) do (set /p com=<%1\%2
- 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!)
- exit
- :configerrn
- echo 配置文件可能存在问题,加载失败,请检查config.ldt。
- pause
- exit
- :dbgn
- @echo on
- for /f "delims=" %%u in (%1\%2) do (set /p com=<%1\%2
- if "!com!" equ help %1\%2
- if "!com1" 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)
- exit
复制代码
作者: Batcher 时间: 2023-7-2 21:07
回复 22# LTSC1809
参考:
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |