How to “hide” a text from Batch-File?
up vote
1
down vote
favorite
I want to know if there any solution to this:
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'
if the User typed an invalid command, it will show like what CMD does ( 'command' is not recongnized...)
What i want to do is to replace the CMD invalid command text to my own one like "command" is an invalid command, but to do that i need to "hide" the CMD one (because if the user typed a invalid command it will not show him a "custom message")
I tried to use some Batch plugins like batbox, CursorPos etc... To replace the cursor position but i didn't get what i wanted. So if anyone have a solution i will be very appreciated!
- Have a nice day, and thanks for reading!
batch-file text plugins cursor-position
|
show 2 more comments
up vote
1
down vote
favorite
I want to know if there any solution to this:
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'
if the User typed an invalid command, it will show like what CMD does ( 'command' is not recongnized...)
What i want to do is to replace the CMD invalid command text to my own one like "command" is an invalid command, but to do that i need to "hide" the CMD one (because if the user typed a invalid command it will not show him a "custom message")
I tried to use some Batch plugins like batbox, CursorPos etc... To replace the cursor position but i didn't get what i wanted. So if anyone have a solution i will be very appreciated!
- Have a nice day, and thanks for reading!
batch-file text plugins cursor-position
you can check if the command exists with this - ss64.com/nt/syntax-which.html . Also errorlevel is set to 9009 when the command is non existent.
– npocmaka
Nov 10 at 15:09
Use thechoice
command or another method which limits the end user to only valid entries!
– Compo
Nov 10 at 15:09
Thanks for the answers, as you can see in my post the %firstresponse%%executeparttwo% means what the user typed will get executed as a command and if the command was invalid it will print the 'command' is not recongnized... And what i want to do is to "hide" that message and replace it by my own one. -Have a nice day!
– Sheep1Coder
Nov 10 at 15:26
As you can see in my comment, if you code your script to only accept valid entries/commands, then you don't need to hide 'not recognized' messages, because there won't be any!
– Compo
Nov 10 at 15:28
@Compo I tried thechoice
command but it won't let you type a long command such asdel
with it syntax or a custom commandsapt-get update
etc... It only accept one single lettre, Thanks for the answer! -Have a nice day!
– Sheep1Coder
Nov 10 at 15:34
|
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to know if there any solution to this:
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'
if the User typed an invalid command, it will show like what CMD does ( 'command' is not recongnized...)
What i want to do is to replace the CMD invalid command text to my own one like "command" is an invalid command, but to do that i need to "hide" the CMD one (because if the user typed a invalid command it will not show him a "custom message")
I tried to use some Batch plugins like batbox, CursorPos etc... To replace the cursor position but i didn't get what i wanted. So if anyone have a solution i will be very appreciated!
- Have a nice day, and thanks for reading!
batch-file text plugins cursor-position
I want to know if there any solution to this:
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'
if the User typed an invalid command, it will show like what CMD does ( 'command' is not recongnized...)
What i want to do is to replace the CMD invalid command text to my own one like "command" is an invalid command, but to do that i need to "hide" the CMD one (because if the user typed a invalid command it will not show him a "custom message")
I tried to use some Batch plugins like batbox, CursorPos etc... To replace the cursor position but i didn't get what i wanted. So if anyone have a solution i will be very appreciated!
- Have a nice day, and thanks for reading!
batch-file text plugins cursor-position
batch-file text plugins cursor-position
asked Nov 10 at 14:46
Sheep1Coder
86
86
you can check if the command exists with this - ss64.com/nt/syntax-which.html . Also errorlevel is set to 9009 when the command is non existent.
– npocmaka
Nov 10 at 15:09
Use thechoice
command or another method which limits the end user to only valid entries!
– Compo
Nov 10 at 15:09
Thanks for the answers, as you can see in my post the %firstresponse%%executeparttwo% means what the user typed will get executed as a command and if the command was invalid it will print the 'command' is not recongnized... And what i want to do is to "hide" that message and replace it by my own one. -Have a nice day!
– Sheep1Coder
Nov 10 at 15:26
As you can see in my comment, if you code your script to only accept valid entries/commands, then you don't need to hide 'not recognized' messages, because there won't be any!
– Compo
Nov 10 at 15:28
@Compo I tried thechoice
command but it won't let you type a long command such asdel
with it syntax or a custom commandsapt-get update
etc... It only accept one single lettre, Thanks for the answer! -Have a nice day!
– Sheep1Coder
Nov 10 at 15:34
|
show 2 more comments
you can check if the command exists with this - ss64.com/nt/syntax-which.html . Also errorlevel is set to 9009 when the command is non existent.
– npocmaka
Nov 10 at 15:09
Use thechoice
command or another method which limits the end user to only valid entries!
– Compo
Nov 10 at 15:09
Thanks for the answers, as you can see in my post the %firstresponse%%executeparttwo% means what the user typed will get executed as a command and if the command was invalid it will print the 'command' is not recongnized... And what i want to do is to "hide" that message and replace it by my own one. -Have a nice day!
– Sheep1Coder
Nov 10 at 15:26
As you can see in my comment, if you code your script to only accept valid entries/commands, then you don't need to hide 'not recognized' messages, because there won't be any!
– Compo
Nov 10 at 15:28
@Compo I tried thechoice
command but it won't let you type a long command such asdel
with it syntax or a custom commandsapt-get update
etc... It only accept one single lettre, Thanks for the answer! -Have a nice day!
– Sheep1Coder
Nov 10 at 15:34
you can check if the command exists with this - ss64.com/nt/syntax-which.html . Also errorlevel is set to 9009 when the command is non existent.
– npocmaka
Nov 10 at 15:09
you can check if the command exists with this - ss64.com/nt/syntax-which.html . Also errorlevel is set to 9009 when the command is non existent.
– npocmaka
Nov 10 at 15:09
Use the
choice
command or another method which limits the end user to only valid entries!– Compo
Nov 10 at 15:09
Use the
choice
command or another method which limits the end user to only valid entries!– Compo
Nov 10 at 15:09
Thanks for the answers, as you can see in my post the %firstresponse%%executeparttwo% means what the user typed will get executed as a command and if the command was invalid it will print the 'command' is not recongnized... And what i want to do is to "hide" that message and replace it by my own one. -Have a nice day!
– Sheep1Coder
Nov 10 at 15:26
Thanks for the answers, as you can see in my post the %firstresponse%%executeparttwo% means what the user typed will get executed as a command and if the command was invalid it will print the 'command' is not recongnized... And what i want to do is to "hide" that message and replace it by my own one. -Have a nice day!
– Sheep1Coder
Nov 10 at 15:26
As you can see in my comment, if you code your script to only accept valid entries/commands, then you don't need to hide 'not recognized' messages, because there won't be any!
– Compo
Nov 10 at 15:28
As you can see in my comment, if you code your script to only accept valid entries/commands, then you don't need to hide 'not recognized' messages, because there won't be any!
– Compo
Nov 10 at 15:28
@Compo I tried the
choice
command but it won't let you type a long command such as del
with it syntax or a custom commands apt-get update
etc... It only accept one single lettre, Thanks for the answer! -Have a nice day!– Sheep1Coder
Nov 10 at 15:34
@Compo I tried the
choice
command but it won't let you type a long command such as del
with it syntax or a custom commands apt-get update
etc... It only accept one single lettre, Thanks for the answer! -Have a nice day!– Sheep1Coder
Nov 10 at 15:34
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
Your splitting the command and parameters is not ideal, there is a much easier and safer way. Also, the method of an own subroutine for each command is suboptimal (especially, when you add more and more commands).
@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 "_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 :input
(Note to experienced batch users: yes I know there is a possibility for some "code injection")
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Your splitting the command and parameters is not ideal, there is a much easier and safer way. Also, the method of an own subroutine for each command is suboptimal (especially, when you add more and more commands).
@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 "_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 :input
(Note to experienced batch users: yes I know there is a possibility for some "code injection")
add a comment |
up vote
1
down vote
Your splitting the command and parameters is not ideal, there is a much easier and safer way. Also, the method of an own subroutine for each command is suboptimal (especially, when you add more and more commands).
@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 "_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 :input
(Note to experienced batch users: yes I know there is a possibility for some "code injection")
add a comment |
up vote
1
down vote
up vote
1
down vote
Your splitting the command and parameters is not ideal, there is a much easier and safer way. Also, the method of an own subroutine for each command is suboptimal (especially, when you add more and more commands).
@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 "_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 :input
(Note to experienced batch users: yes I know there is a possibility for some "code injection")
Your splitting the command and parameters is not ideal, there is a much easier and safer way. Also, the method of an own subroutine for each command is suboptimal (especially, when you add more and more commands).
@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 "_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 :input
(Note to experienced batch users: yes I know there is a possibility for some "code injection")
answered Nov 10 at 17:55
Stephan
33.6k43152
33.6k43152
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240075%2fhow-to-hide-a-text-from-batch-file%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
you can check if the command exists with this - ss64.com/nt/syntax-which.html . Also errorlevel is set to 9009 when the command is non existent.
– npocmaka
Nov 10 at 15:09
Use the
choice
command or another method which limits the end user to only valid entries!– Compo
Nov 10 at 15:09
Thanks for the answers, as you can see in my post the %firstresponse%%executeparttwo% means what the user typed will get executed as a command and if the command was invalid it will print the 'command' is not recongnized... And what i want to do is to "hide" that message and replace it by my own one. -Have a nice day!
– Sheep1Coder
Nov 10 at 15:26
As you can see in my comment, if you code your script to only accept valid entries/commands, then you don't need to hide 'not recognized' messages, because there won't be any!
– Compo
Nov 10 at 15:28
@Compo I tried the
choice
command but it won't let you type a long command such asdel
with it syntax or a custom commandsapt-get update
etc... It only accept one single lettre, Thanks for the answer! -Have a nice day!– Sheep1Coder
Nov 10 at 15:34