如何 "hide" 来自批处理文件的文本?
How to "hide" a text from Batch-File?
我想知道有没有解决办法:
Main.bat:
@echo off
goto 'input'
: 'input'
cls
set "inp="
set /p inp=What would you like to do?
set firstresponse=%inp:~0,5%
if %firstresponse%==help goto 'help'
pause
if /I %firstresponse%==check set firstresponse=dir && set
executeparttwo=%inp:~5%
if /I %firstresponse%==remov goto 'remove'
%firstresponse%%executeparttwo%
pause
goto 'input'
: 'remove'
set "firstresponse=" && set firstresponse=%inp:~0,6%
if /I %firstresponse%==remove set firstresponse=del
set executeparttwo=%inp:~6%
%firstresponse%%executeparttwo%
pause
goto 'input'
: 'help'
cls
echo Check = Dir in regular command prompt, checks a directory.
echo Remove = del in regular command prompt, deletes something.
pause
goto 'input'
如果用户键入了无效命令,它会像 CMD 一样显示('command' 无法识别...)
我想做的是将 CMD 无效命令文本替换为我自己的命令文本,例如 "command" 是无效命令,但为此我需要 "hide" CMD 文本(因为如果用户键入了无效命令,它不会向他显示 "custom message")
我尝试使用一些 Batch 插件,如 batbox、CursorPos 等...来替换光标位置,但我没有得到我想要的。因此,如果有人有解决方案,我将不胜感激!
- 祝你今天愉快,感谢阅读!
你的命令和参数拆分不理想,有一种更简单、更安全的方法。此外,每个命令都有一个自己的子程序的方法不是最理想的(尤其是当您添加越来越多的命令时)。
@echo off
call :commandlist REM build translation table
:input
REM get input line:
set /p "commandline=Enter Command: "
REM split to command and parameters
for /f "tokens=1,*" %%a in ("%commandline%") do (
set "command=_%%a"
set "params=%%b"
)
REM check for valid command:
set _|findstr /bi "%command%=" >nul || (
echo invalid command: '%command:~1%'.
goto :input
)
REM execute the command:
call %%%command%%% %params%
goto :input
:Commandlist
set "_check=dir /b"
set "_remove=del"
set "_help=:help"
set "_where=call echo %%cd%%"
set "_change=cd"
set "_apt-get=:apt"
set "_bye=exit /b" 'secret' exit command ;)
goto :eof
:help
echo Check = Dir in regular command prompt, checks a directory.
echo Remove = del in regular command prompt, deletes something.
echo Where = echo %%cd%% in regular command prompt, print working folder.
echo Change = cd in regular command prompt, change working folder
goto :eof
:apt
if /i "%~1" == "update" echo updating... & goto :eof
if /i "%~1" == "whatever" echo whatevering... & goto :eof
echo invalid command: '%command:~1% %1'
goto :eof
(有经验的批处理用户请注意:是的,我知道有些人可能 "code injection")
我想知道有没有解决办法:
Main.bat:
@echo off
goto 'input'
: 'input'
cls
set "inp="
set /p inp=What would you like to do?
set firstresponse=%inp:~0,5%
if %firstresponse%==help goto 'help'
pause
if /I %firstresponse%==check set firstresponse=dir && set
executeparttwo=%inp:~5%
if /I %firstresponse%==remov goto 'remove'
%firstresponse%%executeparttwo%
pause
goto 'input'
: 'remove'
set "firstresponse=" && set firstresponse=%inp:~0,6%
if /I %firstresponse%==remove set firstresponse=del
set executeparttwo=%inp:~6%
%firstresponse%%executeparttwo%
pause
goto 'input'
: 'help'
cls
echo Check = Dir in regular command prompt, checks a directory.
echo Remove = del in regular command prompt, deletes something.
pause
goto 'input'
如果用户键入了无效命令,它会像 CMD 一样显示('command' 无法识别...)
我想做的是将 CMD 无效命令文本替换为我自己的命令文本,例如 "command" 是无效命令,但为此我需要 "hide" CMD 文本(因为如果用户键入了无效命令,它不会向他显示 "custom message")
我尝试使用一些 Batch 插件,如 batbox、CursorPos 等...来替换光标位置,但我没有得到我想要的。因此,如果有人有解决方案,我将不胜感激!
- 祝你今天愉快,感谢阅读!
你的命令和参数拆分不理想,有一种更简单、更安全的方法。此外,每个命令都有一个自己的子程序的方法不是最理想的(尤其是当您添加越来越多的命令时)。
@echo off
call :commandlist REM build translation table
:input
REM get input line:
set /p "commandline=Enter Command: "
REM split to command and parameters
for /f "tokens=1,*" %%a in ("%commandline%") do (
set "command=_%%a"
set "params=%%b"
)
REM check for valid command:
set _|findstr /bi "%command%=" >nul || (
echo invalid command: '%command:~1%'.
goto :input
)
REM execute the command:
call %%%command%%% %params%
goto :input
:Commandlist
set "_check=dir /b"
set "_remove=del"
set "_help=:help"
set "_where=call echo %%cd%%"
set "_change=cd"
set "_apt-get=:apt"
set "_bye=exit /b" 'secret' exit command ;)
goto :eof
:help
echo Check = Dir in regular command prompt, checks a directory.
echo Remove = del in regular command prompt, deletes something.
echo Where = echo %%cd%% in regular command prompt, print working folder.
echo Change = cd in regular command prompt, change working folder
goto :eof
:apt
if /i "%~1" == "update" echo updating... & goto :eof
if /i "%~1" == "whatever" echo whatevering... & goto :eof
echo invalid command: '%command:~1% %1'
goto :eof
(有经验的批处理用户请注意:是的,我知道有些人可能 "code injection")