标题: [其他] 自制命令行没问题,把它改成解释器就不能用了 [打印本页]
作者: LTSC1809 时间: 2023-7-3 13:36 标题: 自制命令行没问题,把它改成解释器就不能用了
我做了一个升级版的命令行,代码如下:- @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几个字)
复制代码
一个帖子有字数限制,另一部分发到二楼。
作者: LTSC1809 时间: 2023-7-3 13:36
现在做了一个解释器,逐行获取文本里的内容并执行,使用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-3 13:52
回复 2# LTSC1809
每行代码下面加一行:
pause
观察一下是在第几行代码“闪退”的?
作者: LTSC1809 时间: 2023-7-3 18:04
回复 3# Batcher
58行有个exit,所以退出了。但是去掉exit,则会直接显示配置文件存在问题。配置文件存在问题那个是59行的:configerr 那个标签。按理说会执行循环体,然后执行完循环体也就是文本的每一行都执行完了,就会碰到exit退出,但明明那个exit前面是一个for循环,循环提取文件每行内容并执行,为什么会不执行循环而是直接跑到后面的exit呢
作者: LTSC1809 时间: 2023-7-3 18:06
回复 3# Batcher
这是我通过call命令运行这个闪退的文件并且后面加上>1.txt 产生的“日志文件”,回显我开了,所以它记录了脚本退出前执行过的每一条命令,可以参考一下:- C:\Users\Administrator>SetLocal EnableDelayedExpansion
-
- C:\Users\Administrator>for /F "delims=; tokens=5" %q in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do if %q EQU true goto noecho
-
- C:\Users\Administrator>if true EQU true goto noecho
-
- C:\Users\Administrator>for /F "delims=; tokens=1" %o in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do set conls=%o
-
- C:\Users\Administrator>set conls=100'30
-
- C:\Users\Administrator>for /F "delims=' tokens=1" %z in ("100'30") do set modc=%z
-
- C:\Users\Administrator>set modc=100
-
- C:\Users\Administrator>for /F "delims=' tokens=2" %e in ("100'30") do set modl=%e
-
- C:\Users\Administrator>set modl=30
-
- C:\Users\Administrator>for /F "delims=; tokens=2" %i in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do set dbg=%i
-
- C:\Users\Administrator>set dbg=false
-
- C:\Users\Administrator>for /F "delims=; tokens=3" %t in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do set dk=%t
-
- C:\Users\Administrator>set dk=true
-
- C:\Users\Administrator>for /F "delims=; tokens=4" %b in (C:\Users\Administrator\Desktop\bcitest\config.ldt) do set color=%b
-
- C:\Users\Administrator>set color=0a
-
- C:\Users\Administrator>if false EQU true (set dbgx=a ) else (if false EQU false (set dbgx=b ) else (goto configerr ) )
-
- C:\Users\Administrator>if true EQU true (set dkif=a ) else (if true EQU false (set dkif=b ) else (goto configerr ) )
-
- 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
-
- C:\Users\Administrator>if 0a EQU 01 goto colok
-
- C:\Users\Administrator>if 0a EQU 02 goto colok
-
- C:\Users\Administrator>if 0a EQU 03 goto colok
-
- C:\Users\Administrator>if 0a EQU 04 goto colok
-
- C:\Users\Administrator>if 0a EQU 05 goto colok
-
- C:\Users\Administrator>if 0a EQU 06 goto colok
-
- C:\Users\Administrator>if 0a EQU 07 goto colok
-
- C:\Users\Administrator>if 0a EQU 08 goto colok
-
- C:\Users\Administrator>if 0a EQU 09 goto colok
-
- C:\Users\Administrator>if 0a EQU 0a goto colok
-
- C:\Users\Administrator>rem time
-
- C:\Users\Administrator>set "t1x=17:59:56.20"
-
- C:\Users\Administrator>if "17" LSS "~,2" set "add=+24"
-
- 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"
-
- C:\Users\Administrator>rem endtime
-
- C:\Users\Administrator>if a EQU b goto nodk
-
- C:\Users\Administrator>rem time
-
- C:\Users\Administrator>set "tn=17:59:56.20"
-
- C:\Users\Administrator>rem code
-
- C:\Users\Administrator>for /F "delims=" %a in (C:\Users\Administrator\doskey.ldt) do doskey %a
-
- C:\Users\Administrator>rem time
-
- C:\Users\Administrator>set "t1n=17:59:56.20"
-
- C:\Users\Administrator>if "17" LSS "17" set "add=+24"
-
- 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"
-
- C:\Users\Administrator>rem time
-
- C:\Users\Administrator>set "t1=17:59:56.21"
-
- C:\Users\Administrator>if "17" LSS "~,2" set "add=+24"
-
- 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"
-
- C:\Users\Administrator>color 0a
-
- C:\Users\Administrator>mode con cols=100 lines=30
-
- C:\Users\Administrator>if b EQU a goto dbg
-
- C:\Users\Administrator>echo 加载文件:
- 加载文件:
-
- C:\Users\Administrator>echo 加载配置文件...
- 加载配置文件...
-
- C:\Users\Administrator>echo 完成 用时::.(时:分:秒.毫秒)
- 完成 用时::.(时:分:秒.毫秒)
-
- C:\Users\Administrator>echo 加载宏命令...
- 加载宏命令...
-
- C:\Users\Administrator>echo 完成 用时0:0:0.0(时:分:秒.毫秒)
- 完成 用时0:0:0.0(时:分:秒.毫秒)
-
- C:\Users\Administrator>echo 加载完成 总用时::.(时:分:秒.毫秒)
- 加载完成 总用时::.(时:分:秒.毫秒)
-
- C:\Users\Administrator>echo.
-
-
- C:\Users\Administrator>echo BetterCommand Interpreter development version 0.1a
- BetterCommand Interpreter development version 0.1a
-
- C:\Users\Administrator>echo.
-
-
- C:\Users\Administrator>for /F "delims=" %r in (C:\Users\Administrator\Desktop\bcitest\114.bat) do (
- set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat
- if "!com!" EQU help C:\Users\Administrator\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!
- )
-
- C:\Users\Administrator>(
- set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat
- if "!com!" EQU help C:\Users\Administrator\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!
- )
-
- C:\Users\Administrator>(
- set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat
- if "!com!" EQU help C:\Users\Administrator\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!
- )
-
- C:\Users\Administrator>(
- set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat
- if "!com!" EQU help C:\Users\Administrator\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!
- )
-
- C:\Users\Administrator>(
- set /p !com!= 0<C:\Users\Administrator\Desktop\bcitest\114.bat
- if "!com!" EQU help C:\Users\Administrator\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!
- )
-
- C:\Users\Administrator>exit
复制代码
作者: LTSC1809 时间: 2023-7-3 18:11
回复 5# LTSC1809
其中114.bat是我call中附带的参数,它的内容如下:- @echo off
- mc
- echo a
- pause
复制代码
其中的mc这一行是doskey.ldt中定义的语句。它文件夹下的doskey.ldt和config.ldt内容如下,不知道这两个文件有什么用的话可以去看看这个帖子,也是我写的,去看看1楼和23楼,这两层说明了它们的作用:http://www.bathome.net/thread-66697-2-1.html
作者: jyswjjgdwtdtj 时间: 2023-7-3 18:13
如果你只是要屏闭输出 直接>nul 不就行了
作者: LTSC1809 时间: 2023-7-3 18:13
回复 5# LTSC1809
那个set /p 变量=<路径 那里可以看到有个0在<前面,但是我去看了源码,根本没有出现0,我也不知道为啥有个0
作者: LTSC1809 时间: 2023-7-3 18:14
回复 7# jyswjjgdwtdtj
没太看明白你的意思,我并不是要屏蔽什么输出
作者: Batcher 时间: 2023-7-3 18:25
回复 4# LTSC1809
第一步,把代码里面所有的exit全部改成exit /b
第二步,按照3楼的方法执行代码
第三步,说一下你认为第几行代码执行结果跟你的期望不同
作者: LTSC1809 时间: 2023-7-3 18:28
本帖最后由 LTSC1809 于 2023-7-3 20:16 编辑
回复 11# Batcher
弄好的代码如下:- @echo off
- pause
- SetLocal EnableDelayedExpansion
- pause
- for /f "delims=; tokens=5" %%q in (%1\config.ldt) do if %%q equ true goto noecho
- pause
- rem time
- pause
- set "t=%time%"
- pause
- rem code
- pause
- rem time
- pause
- set "tx=%time%"
- pause
- rem code
- pause
- for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
- pause
- for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
- pause
- for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
- pause
- for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
- pause
- for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
- pause
- for /f "delims=; tokens=4" %%b in (%1\config.ldt) do set color=%%b
- pause
- if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
- pause
- if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
- pause
- 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
- pause
- goto configerr
- pause
- :colok
- pause
- rem time
- pause
- set "t1x=%time%"
- pause
- if "%t1x:~,2%" lss "%tx:~,2%" set "add=+24"
- pause
- 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"
- pause
- rem endtime
- pause
- if %dkif% equ b goto nodk
- pause
- rem time
- pause
- set "tn=%time%"
- pause
- rem code
- pause
- for /f "delims=" %%a in (%cd%\doskey.ldt) do doskey %%a
- pause
- rem time
- pause
- set "t1n=%time%"
- pause
- if "%t1n:~,2%" lss "%tn:~,2%" set "add=+24"
- pause
- 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"
- pause
- :nodk
- pause
- rem time
- pause
- set "t1=%time%"
- pause
- if "%t1:~,2%" lss "%t:~,2%" set "add=+24"
- pause
- 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"
- pause
- color %color%
- pause
- mode con cols=%modc% lines=%modl%
- pause
- if %dbgx% equ a goto dbg
- pause
- echo 加载文件:
- pause
- echo 加载配置文件...
- pause
- echo 完成 用时%hhx%:%mmx%:%ssx%.%msx%(时:分:秒.毫秒)
- pause
- echo 加载宏命令...
- pause
- echo 完成 用时%hhn%:%mmn%:%ssn%.%msn%(时:分:秒.毫秒)
- pause
- echo 加载完成 总用时%hh%:%mm%:%ss%.%ms%(时:分:秒.毫秒)
- pause
- echo.
- pause
- echo BetterCommand Interpreter development version 0.1a
- pause
- echo.
- pause
- for /f "delims=" %%r in (%1\%2) do (set /p !com!=<%1\%2
- pause
- if "!com!" equ help %cd%\help.txt
- pause
- if "!com!" equ exit /b exit /b
- pause
- if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
- pause
- if "!shutyn!" equ y shutdown /s /t 0 /f)
- pause
- !com!)
- pause
- exit /b
- pause
- :configerr
- pause
- echo 配置文件可能存在问题,加载失败,请检查config.ldt。
- pause
- pause
- pause
- exit /b
- pause
- :dbg
- pause
- @echo on
- pause
- for /f "delims=" %%w in (%1\%2) do (set /p com=<%1\%2
- pause
- if "!com!" equ help %cd%\help.txt
- pause
- if "!com!" equ exit /b exit /b
- pause
- if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
- pause
- if "!shutyn!" equ y shutdown /s /t 0 /f)
- pause
- !com!)
- pause
- exit /b
- pause
- exit /b
- pause
- pause
- pause
- :noecho
- pause
- for /f "delims=; tokens=1" %%o in (%1\config.ldt) do set conls=%%o
- pause
- for /f "delims=' tokens=1" %%z in ("%conls%") do set modc=%%z
- pause
- for /f "delims=' tokens=2" %%e in ("%conls%") do set modl=%%e
- pause
- for /f "delims=; tokens=2" %%i in (%1\config.ldt) do set dbg=%%i
- pause
- for /f "delims=; tokens=3" %%t in (%1\config.ldt) do set dk=%%t
- pause
- for /f "delims=; tokens=4" %%b in (%1\config.ldt) do set color=%%b
- pause
- if %dbg% equ true (set dbgx=a) else (if %dbg% equ false (set dbgx=b) else (goto configerr))
- pause
- if %dk% equ true (set dkif=a) else (if %dk% equ false (set dkif=b) else (goto configerr))
- pause
- 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
- pause
- goto configerr
- pause
- :colokn
- pause
- if %dkif% equ b goto nodk
- pause
- for /f "delims=" %%a in (%1\doskey.ldt) do doskey %%a
- pause
- :nodkn
- pause
- for /f "delims=" %%y in (%1\%2) do (set /p com=<%1\%2
- pause
- if "!com!" equ help %cd%\help.txt
- pause
- if "!com!" equ exit /b exit /b
- pause
- if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
- pause
- if "!shutyn!" equ y shutdown /s /t 0 /f)
- pause
- !com!)
- pause
- exit /b
- pause
- :configerrn
- pause
- echo 配置文件可能存在问题,加载失败,请检查config.ldt。
- pause
- pause
- pause
- exit /b
- pause
- :dbgn
- pause
- @echo on
- pause
- for /f "delims=" %%u in (%1\%2) do (set /p com=<%1\%2
- pause
- if "!com!" equ help %1\%2
- pause
- if "!com1" equ exit /b exit /b
- pause
- if "!com!" equ shutdown (set /p shutyn=Shutdown now?[Y/N]:
- pause
- if "!shutyn!" equ y shutdown /s /t 0 /f)
- pause
- !com!
- pause
- pause)
- pause
- exit /b
复制代码
发现最后一次输出是:- 系统找不到文件 C:\Users\Administrator\Desktop\bcitest\C:\Users\Administrator\Desktop\bcitest\114.bat
复制代码
路径重复了两次,这是怎么回事啊
作者: Batcher 时间: 2023-7-3 19:31
回复 12# LTSC1809
11楼的三步是为了帮你找到代码中的问题,问题解决之后你就怎么高兴怎么改。
作者: jyswjjgdwtdtj 时间: 2023-7-3 20:14
话说没搞懂你到底要干啥
如果只是读取再运行直接- for /f "delims=" %%i in ('type C:\Users\admin\xx\1.txt') do set b=%%i
- %b%
复制代码
不就行了?
作者: LTSC1809 时间: 2023-7-3 20:20
回复 13# jyswjjgdwtdtj
这...%b%要等for执行完才会执行,所以它的内容是%%i最后一次,也就是文档里最后一行的内容
作者: Batcher 时间: 2023-7-4 10:21
回复 14# LTSC1809
13楼代码改成这样试试:- for /f "delims=" %%i in ('type 1.txt') do "%%i"
复制代码
作者: jyswjjgdwtdtj 时间: 2023-7-4 10:45
给你支个招 用vbs 先exec一个cmd窗口 先执行你要用来设定控制台窗口的bat 再执行你要运行bat
作者: LTSC1809 时间: 2023-7-4 12:47
回复 15# Batcher
我还需要if判断是否是那几个命令,不是的话再直接执行,这怎么办
作者: jyswjjgdwtdtj 时间: 2023-7-4 20:04
回复 17# LTSC1809
扔在第一个bat里
作者: BingjianREMIX 时间: 2023-7-5 01:58
要不要考虑一下嵌套cmd
作者: jyswjjgdwtdtj 时间: 2023-7-5 09:03
回复 17# LTSC1809
哦 之前没看懂你的意思
你可以exec一个cmd 然后读取bat 输入到cmd里执行
作者: BingjianREMIX 时间: 2023-7-5 22:53
可以用terminal运行一下,可以显示错误信息
作者: BingjianREMIX 时间: 2023-7-5 22:54
我看了是显示"此时不应有'true'"
作者: BingjianREMIX 时间: 2023-7-5 23:03
处理后是配置文件可能存在问题,加载失败,请检查config.ldt。
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |