How to “hide” a text from Batch-File?











up vote
1
down vote

favorite
1












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!










share|improve this question






















  • 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 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















up vote
1
down vote

favorite
1












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!










share|improve this question






















  • 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 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













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





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!










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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 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


















  • 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 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
















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












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")






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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
































    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")






    share|improve this answer

























      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")






      share|improve this answer























        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")






        share|improve this answer












        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")







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 17:55









        Stephan

        33.6k43152




        33.6k43152






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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




















































































            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine