Problems with inputs w/ spaces in a batch file












1















I have a problem of an input being successful, but not being able to use the IF command with that input. I have already tried:



if "%input%" equ "s helpme" goto localhost.mail.helpme


I have eliminated the possibility of an error in the :debug function, an error in the symbol '.', and the possibility of an error in the set /p input section. I am out of ideas on how the code is going wrong.



I know how to solve the common problem of spaces in batch, but for some reason, this code is still not working for me. Here is the code and the output from the debug file:



:: GAME.BAT

set lvl=003
set debug=true

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 002 goto localhost.mail.help
set /p input=localhost.mail
call :debug "localhost.mail input %input%"
if %input% equ h goto localhost.mail.help
if %input% equ help goto localhost.mail.help
if %input% equ listmail goto localhost.mail.list
if %input% equ l goto localhost.mail.list
if "%input%" equ "s helpme" goto localhost.mail.helpme
if "%input%" equ "show helpme" goto localhost.mail.helpme
if %input% equ e goto localhost
if %input% equ exit goto localhost

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 002 echo Advanced to level 3
if %lvl% equ 002 set lvl=003
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 002 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 003 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if %debug% equ true echo %date% %time% %~1>>debug.txt
GOTO :EOF




:: DEBUG.TXT
Tue 11/20/2018 13:33:05.84 vdir localhost.mail
Tue 11/20/2018 13:33:05.86 vdir localhost.mail.help
Tue 11/20/2018 13:33:05.87 vdir localhost.mail
Tue 11/20/2018 13:33:10.15 localhost.mail input s helpme


At the end of DEBUG.TXT is where the batch window exited from a coding error.










share|improve this question




















  • 7





    You need to have all the IF comparisons use double quotes.

    – Squashman
    Nov 20 '18 at 19:52






  • 4





    The comparison operator EQU is designed primary for integer comparisons and runs a string comparison only if one of the two compared strings cannot be successfully converted to an integer value. So it is better to use == which always makes a string comparison. See Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files for more details.

    – Mofi
    Nov 20 '18 at 20:20






  • 5





    I suggest to read How to stop Windows command interpreter from quitting batch file execution on an incorrect user input? It looks like a menu with CHOICE would be better for this task and definitely much more secure and fault-tolerant than the prompt solution used by you which gives the user the freedom to enter really any string. Debugging a batch file could be also of interest for you.

    – Mofi
    Nov 20 '18 at 20:24


















1















I have a problem of an input being successful, but not being able to use the IF command with that input. I have already tried:



if "%input%" equ "s helpme" goto localhost.mail.helpme


I have eliminated the possibility of an error in the :debug function, an error in the symbol '.', and the possibility of an error in the set /p input section. I am out of ideas on how the code is going wrong.



I know how to solve the common problem of spaces in batch, but for some reason, this code is still not working for me. Here is the code and the output from the debug file:



:: GAME.BAT

set lvl=003
set debug=true

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 002 goto localhost.mail.help
set /p input=localhost.mail
call :debug "localhost.mail input %input%"
if %input% equ h goto localhost.mail.help
if %input% equ help goto localhost.mail.help
if %input% equ listmail goto localhost.mail.list
if %input% equ l goto localhost.mail.list
if "%input%" equ "s helpme" goto localhost.mail.helpme
if "%input%" equ "show helpme" goto localhost.mail.helpme
if %input% equ e goto localhost
if %input% equ exit goto localhost

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 002 echo Advanced to level 3
if %lvl% equ 002 set lvl=003
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 002 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 003 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if %debug% equ true echo %date% %time% %~1>>debug.txt
GOTO :EOF




:: DEBUG.TXT
Tue 11/20/2018 13:33:05.84 vdir localhost.mail
Tue 11/20/2018 13:33:05.86 vdir localhost.mail.help
Tue 11/20/2018 13:33:05.87 vdir localhost.mail
Tue 11/20/2018 13:33:10.15 localhost.mail input s helpme


At the end of DEBUG.TXT is where the batch window exited from a coding error.










share|improve this question




















  • 7





    You need to have all the IF comparisons use double quotes.

    – Squashman
    Nov 20 '18 at 19:52






  • 4





    The comparison operator EQU is designed primary for integer comparisons and runs a string comparison only if one of the two compared strings cannot be successfully converted to an integer value. So it is better to use == which always makes a string comparison. See Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files for more details.

    – Mofi
    Nov 20 '18 at 20:20






  • 5





    I suggest to read How to stop Windows command interpreter from quitting batch file execution on an incorrect user input? It looks like a menu with CHOICE would be better for this task and definitely much more secure and fault-tolerant than the prompt solution used by you which gives the user the freedom to enter really any string. Debugging a batch file could be also of interest for you.

    – Mofi
    Nov 20 '18 at 20:24
















1












1








1








I have a problem of an input being successful, but not being able to use the IF command with that input. I have already tried:



if "%input%" equ "s helpme" goto localhost.mail.helpme


I have eliminated the possibility of an error in the :debug function, an error in the symbol '.', and the possibility of an error in the set /p input section. I am out of ideas on how the code is going wrong.



I know how to solve the common problem of spaces in batch, but for some reason, this code is still not working for me. Here is the code and the output from the debug file:



:: GAME.BAT

set lvl=003
set debug=true

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 002 goto localhost.mail.help
set /p input=localhost.mail
call :debug "localhost.mail input %input%"
if %input% equ h goto localhost.mail.help
if %input% equ help goto localhost.mail.help
if %input% equ listmail goto localhost.mail.list
if %input% equ l goto localhost.mail.list
if "%input%" equ "s helpme" goto localhost.mail.helpme
if "%input%" equ "show helpme" goto localhost.mail.helpme
if %input% equ e goto localhost
if %input% equ exit goto localhost

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 002 echo Advanced to level 3
if %lvl% equ 002 set lvl=003
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 002 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 003 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if %debug% equ true echo %date% %time% %~1>>debug.txt
GOTO :EOF




:: DEBUG.TXT
Tue 11/20/2018 13:33:05.84 vdir localhost.mail
Tue 11/20/2018 13:33:05.86 vdir localhost.mail.help
Tue 11/20/2018 13:33:05.87 vdir localhost.mail
Tue 11/20/2018 13:33:10.15 localhost.mail input s helpme


At the end of DEBUG.TXT is where the batch window exited from a coding error.










share|improve this question
















I have a problem of an input being successful, but not being able to use the IF command with that input. I have already tried:



if "%input%" equ "s helpme" goto localhost.mail.helpme


I have eliminated the possibility of an error in the :debug function, an error in the symbol '.', and the possibility of an error in the set /p input section. I am out of ideas on how the code is going wrong.



I know how to solve the common problem of spaces in batch, but for some reason, this code is still not working for me. Here is the code and the output from the debug file:



:: GAME.BAT

set lvl=003
set debug=true

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 002 goto localhost.mail.help
set /p input=localhost.mail
call :debug "localhost.mail input %input%"
if %input% equ h goto localhost.mail.help
if %input% equ help goto localhost.mail.help
if %input% equ listmail goto localhost.mail.list
if %input% equ l goto localhost.mail.list
if "%input%" equ "s helpme" goto localhost.mail.helpme
if "%input%" equ "show helpme" goto localhost.mail.helpme
if %input% equ e goto localhost
if %input% equ exit goto localhost

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 002 echo Advanced to level 3
if %lvl% equ 002 set lvl=003
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 002 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 003 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if %debug% equ true echo %date% %time% %~1>>debug.txt
GOTO :EOF




:: DEBUG.TXT
Tue 11/20/2018 13:33:05.84 vdir localhost.mail
Tue 11/20/2018 13:33:05.86 vdir localhost.mail.help
Tue 11/20/2018 13:33:05.87 vdir localhost.mail
Tue 11/20/2018 13:33:10.15 localhost.mail input s helpme


At the end of DEBUG.TXT is where the batch window exited from a coding error.







batch-file input






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 20:57









michael_heath

2,8872617




2,8872617










asked Nov 20 '18 at 19:47









user8385393user8385393

83




83








  • 7





    You need to have all the IF comparisons use double quotes.

    – Squashman
    Nov 20 '18 at 19:52






  • 4





    The comparison operator EQU is designed primary for integer comparisons and runs a string comparison only if one of the two compared strings cannot be successfully converted to an integer value. So it is better to use == which always makes a string comparison. See Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files for more details.

    – Mofi
    Nov 20 '18 at 20:20






  • 5





    I suggest to read How to stop Windows command interpreter from quitting batch file execution on an incorrect user input? It looks like a menu with CHOICE would be better for this task and definitely much more secure and fault-tolerant than the prompt solution used by you which gives the user the freedom to enter really any string. Debugging a batch file could be also of interest for you.

    – Mofi
    Nov 20 '18 at 20:24
















  • 7





    You need to have all the IF comparisons use double quotes.

    – Squashman
    Nov 20 '18 at 19:52






  • 4





    The comparison operator EQU is designed primary for integer comparisons and runs a string comparison only if one of the two compared strings cannot be successfully converted to an integer value. So it is better to use == which always makes a string comparison. See Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files for more details.

    – Mofi
    Nov 20 '18 at 20:20






  • 5





    I suggest to read How to stop Windows command interpreter from quitting batch file execution on an incorrect user input? It looks like a menu with CHOICE would be better for this task and definitely much more secure and fault-tolerant than the prompt solution used by you which gives the user the freedom to enter really any string. Debugging a batch file could be also of interest for you.

    – Mofi
    Nov 20 '18 at 20:24










7




7





You need to have all the IF comparisons use double quotes.

– Squashman
Nov 20 '18 at 19:52





You need to have all the IF comparisons use double quotes.

– Squashman
Nov 20 '18 at 19:52




4




4





The comparison operator EQU is designed primary for integer comparisons and runs a string comparison only if one of the two compared strings cannot be successfully converted to an integer value. So it is better to use == which always makes a string comparison. See Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files for more details.

– Mofi
Nov 20 '18 at 20:20





The comparison operator EQU is designed primary for integer comparisons and runs a string comparison only if one of the two compared strings cannot be successfully converted to an integer value. So it is better to use == which always makes a string comparison. See Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files for more details.

– Mofi
Nov 20 '18 at 20:20




5




5





I suggest to read How to stop Windows command interpreter from quitting batch file execution on an incorrect user input? It looks like a menu with CHOICE would be better for this task and definitely much more secure and fault-tolerant than the prompt solution used by you which gives the user the freedom to enter really any string. Debugging a batch file could be also of interest for you.

– Mofi
Nov 20 '18 at 20:24







I suggest to read How to stop Windows command interpreter from quitting batch file execution on an incorrect user input? It looks like a menu with CHOICE would be better for this task and definitely much more secure and fault-tolerant than the prompt solution used by you which gives the user the freedom to enter really any string. Debugging a batch file could be also of interest for you.

– Mofi
Nov 20 '18 at 20:24














1 Answer
1






active

oldest

votes


















1














:: GAME.BAT
set "lvl=3"
set "debug=true"

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 2 goto localhost.mail.help
set /p "input=localhost.mail: "
call :debug "localhost.mail input %input%"
if /i "%input%" == "h" goto localhost.mail.help
if /i "%input%" == "help" goto localhost.mail.help
if /i "%input%" == "l" goto localhost.mail.list
if /i "%input%" == "listmail" goto localhost.mail.list
if /i "%input%" == "s" goto localhost.mail.helpme
if /i "%input%" == "show helpme" goto localhost.mail.helpme
if /i "%input%" == "e" goto :eof
if /i "%input%" == "exit" goto :eof
goto localhost.mail

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 2 echo Advanced to level 3
if %lvl% equ 2 set "lvl=3"
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 2 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 3 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if /i "%debug%" == "true" >> debug.txt echo %date% %time% %~1
goto :eof


Minor fixes done mentioned below:



Double quoted string comparisons used with if. Used argument /i to make comparison case insensitive. String comparisons handled with ==.



Replaced numbers with decimal equivalents i.e. 003 to 3. Leading 0s can be interpreted as octal numbers.



Double quoted set command argument to avoid possible trailing spaces.



Selection exit now goes to the end of file (goto :eof).



Enabled s to show helpme.






share|improve this answer


























  • You could minimise the lines by replacing, for example, if /i "%input%" == "e" goto :eof and if /i "%input%" == "exit" goto :eof with If /I "%input:~,1%"=="e" GoTo :EOF.

    – Compo
    Nov 20 '18 at 23:26






  • 1





    @Compo True, though anything starting with e could be interpreted as exit i.e. elephant would be accepted.

    – michael_heath
    Nov 21 '18 at 5:11











  • I did want to apologize for the messy code- because I was still working on making the code actually work, I wasn’t in the process of cleaning up the code I left behind. Thanks a bunch for this solution.

    – user8385393
    Nov 21 '18 at 17:51











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',
autoActivateHeartbeat: false,
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%2f53400494%2fproblems-with-inputs-w-spaces-in-a-batch-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














:: GAME.BAT
set "lvl=3"
set "debug=true"

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 2 goto localhost.mail.help
set /p "input=localhost.mail: "
call :debug "localhost.mail input %input%"
if /i "%input%" == "h" goto localhost.mail.help
if /i "%input%" == "help" goto localhost.mail.help
if /i "%input%" == "l" goto localhost.mail.list
if /i "%input%" == "listmail" goto localhost.mail.list
if /i "%input%" == "s" goto localhost.mail.helpme
if /i "%input%" == "show helpme" goto localhost.mail.helpme
if /i "%input%" == "e" goto :eof
if /i "%input%" == "exit" goto :eof
goto localhost.mail

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 2 echo Advanced to level 3
if %lvl% equ 2 set "lvl=3"
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 2 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 3 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if /i "%debug%" == "true" >> debug.txt echo %date% %time% %~1
goto :eof


Minor fixes done mentioned below:



Double quoted string comparisons used with if. Used argument /i to make comparison case insensitive. String comparisons handled with ==.



Replaced numbers with decimal equivalents i.e. 003 to 3. Leading 0s can be interpreted as octal numbers.



Double quoted set command argument to avoid possible trailing spaces.



Selection exit now goes to the end of file (goto :eof).



Enabled s to show helpme.






share|improve this answer


























  • You could minimise the lines by replacing, for example, if /i "%input%" == "e" goto :eof and if /i "%input%" == "exit" goto :eof with If /I "%input:~,1%"=="e" GoTo :EOF.

    – Compo
    Nov 20 '18 at 23:26






  • 1





    @Compo True, though anything starting with e could be interpreted as exit i.e. elephant would be accepted.

    – michael_heath
    Nov 21 '18 at 5:11











  • I did want to apologize for the messy code- because I was still working on making the code actually work, I wasn’t in the process of cleaning up the code I left behind. Thanks a bunch for this solution.

    – user8385393
    Nov 21 '18 at 17:51
















1














:: GAME.BAT
set "lvl=3"
set "debug=true"

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 2 goto localhost.mail.help
set /p "input=localhost.mail: "
call :debug "localhost.mail input %input%"
if /i "%input%" == "h" goto localhost.mail.help
if /i "%input%" == "help" goto localhost.mail.help
if /i "%input%" == "l" goto localhost.mail.list
if /i "%input%" == "listmail" goto localhost.mail.list
if /i "%input%" == "s" goto localhost.mail.helpme
if /i "%input%" == "show helpme" goto localhost.mail.helpme
if /i "%input%" == "e" goto :eof
if /i "%input%" == "exit" goto :eof
goto localhost.mail

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 2 echo Advanced to level 3
if %lvl% equ 2 set "lvl=3"
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 2 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 3 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if /i "%debug%" == "true" >> debug.txt echo %date% %time% %~1
goto :eof


Minor fixes done mentioned below:



Double quoted string comparisons used with if. Used argument /i to make comparison case insensitive. String comparisons handled with ==.



Replaced numbers with decimal equivalents i.e. 003 to 3. Leading 0s can be interpreted as octal numbers.



Double quoted set command argument to avoid possible trailing spaces.



Selection exit now goes to the end of file (goto :eof).



Enabled s to show helpme.






share|improve this answer


























  • You could minimise the lines by replacing, for example, if /i "%input%" == "e" goto :eof and if /i "%input%" == "exit" goto :eof with If /I "%input:~,1%"=="e" GoTo :EOF.

    – Compo
    Nov 20 '18 at 23:26






  • 1





    @Compo True, though anything starting with e could be interpreted as exit i.e. elephant would be accepted.

    – michael_heath
    Nov 21 '18 at 5:11











  • I did want to apologize for the messy code- because I was still working on making the code actually work, I wasn’t in the process of cleaning up the code I left behind. Thanks a bunch for this solution.

    – user8385393
    Nov 21 '18 at 17:51














1












1








1







:: GAME.BAT
set "lvl=3"
set "debug=true"

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 2 goto localhost.mail.help
set /p "input=localhost.mail: "
call :debug "localhost.mail input %input%"
if /i "%input%" == "h" goto localhost.mail.help
if /i "%input%" == "help" goto localhost.mail.help
if /i "%input%" == "l" goto localhost.mail.list
if /i "%input%" == "listmail" goto localhost.mail.list
if /i "%input%" == "s" goto localhost.mail.helpme
if /i "%input%" == "show helpme" goto localhost.mail.helpme
if /i "%input%" == "e" goto :eof
if /i "%input%" == "exit" goto :eof
goto localhost.mail

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 2 echo Advanced to level 3
if %lvl% equ 2 set "lvl=3"
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 2 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 3 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if /i "%debug%" == "true" >> debug.txt echo %date% %time% %~1
goto :eof


Minor fixes done mentioned below:



Double quoted string comparisons used with if. Used argument /i to make comparison case insensitive. String comparisons handled with ==.



Replaced numbers with decimal equivalents i.e. 003 to 3. Leading 0s can be interpreted as octal numbers.



Double quoted set command argument to avoid possible trailing spaces.



Selection exit now goes to the end of file (goto :eof).



Enabled s to show helpme.






share|improve this answer















:: GAME.BAT
set "lvl=3"
set "debug=true"

:localhost.mail
call :debug "vdir localhost.mail"
if %lvl% equ 2 goto localhost.mail.help
set /p "input=localhost.mail: "
call :debug "localhost.mail input %input%"
if /i "%input%" == "h" goto localhost.mail.help
if /i "%input%" == "help" goto localhost.mail.help
if /i "%input%" == "l" goto localhost.mail.list
if /i "%input%" == "listmail" goto localhost.mail.list
if /i "%input%" == "s" goto localhost.mail.helpme
if /i "%input%" == "show helpme" goto localhost.mail.helpme
if /i "%input%" == "e" goto :eof
if /i "%input%" == "exit" goto :eof
goto localhost.mail

:localhost.mail.help
call :debug "vdir localhost.mail.help"
if %lvl% equ 2 echo Advanced to level 3
if %lvl% equ 2 set "lvl=3"
echo (h)elp - Display this help screen
echo (l)istmail - Lists emails
echo (s)how - Shows an email ex. show helpme
echo (e)xit - Exits email
goto localhost.mail

:localhost.mail.list
call :debug "vdir localhost.mail.list"
if %lvl% gtr 2 echo helpme
goto localhost.mail

:localhost.mail.helpme
call :debug "vdir localhost.mail.helpme"
if %lvl% lss 3 goto localhost.mail
echo WORK IN PROGRESS, COME BACK NEXT UPDATE!
echo.
goto localhost.mail

:debug
if /i "%debug%" == "true" >> debug.txt echo %date% %time% %~1
goto :eof


Minor fixes done mentioned below:



Double quoted string comparisons used with if. Used argument /i to make comparison case insensitive. String comparisons handled with ==.



Replaced numbers with decimal equivalents i.e. 003 to 3. Leading 0s can be interpreted as octal numbers.



Double quoted set command argument to avoid possible trailing spaces.



Selection exit now goes to the end of file (goto :eof).



Enabled s to show helpme.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 5:41

























answered Nov 20 '18 at 23:04









michael_heathmichael_heath

2,8872617




2,8872617













  • You could minimise the lines by replacing, for example, if /i "%input%" == "e" goto :eof and if /i "%input%" == "exit" goto :eof with If /I "%input:~,1%"=="e" GoTo :EOF.

    – Compo
    Nov 20 '18 at 23:26






  • 1





    @Compo True, though anything starting with e could be interpreted as exit i.e. elephant would be accepted.

    – michael_heath
    Nov 21 '18 at 5:11











  • I did want to apologize for the messy code- because I was still working on making the code actually work, I wasn’t in the process of cleaning up the code I left behind. Thanks a bunch for this solution.

    – user8385393
    Nov 21 '18 at 17:51



















  • You could minimise the lines by replacing, for example, if /i "%input%" == "e" goto :eof and if /i "%input%" == "exit" goto :eof with If /I "%input:~,1%"=="e" GoTo :EOF.

    – Compo
    Nov 20 '18 at 23:26






  • 1





    @Compo True, though anything starting with e could be interpreted as exit i.e. elephant would be accepted.

    – michael_heath
    Nov 21 '18 at 5:11











  • I did want to apologize for the messy code- because I was still working on making the code actually work, I wasn’t in the process of cleaning up the code I left behind. Thanks a bunch for this solution.

    – user8385393
    Nov 21 '18 at 17:51

















You could minimise the lines by replacing, for example, if /i "%input%" == "e" goto :eof and if /i "%input%" == "exit" goto :eof with If /I "%input:~,1%"=="e" GoTo :EOF.

– Compo
Nov 20 '18 at 23:26





You could minimise the lines by replacing, for example, if /i "%input%" == "e" goto :eof and if /i "%input%" == "exit" goto :eof with If /I "%input:~,1%"=="e" GoTo :EOF.

– Compo
Nov 20 '18 at 23:26




1




1





@Compo True, though anything starting with e could be interpreted as exit i.e. elephant would be accepted.

– michael_heath
Nov 21 '18 at 5:11





@Compo True, though anything starting with e could be interpreted as exit i.e. elephant would be accepted.

– michael_heath
Nov 21 '18 at 5:11













I did want to apologize for the messy code- because I was still working on making the code actually work, I wasn’t in the process of cleaning up the code I left behind. Thanks a bunch for this solution.

– user8385393
Nov 21 '18 at 17:51





I did want to apologize for the messy code- because I was still working on making the code actually work, I wasn’t in the process of cleaning up the code I left behind. Thanks a bunch for this solution.

– user8385393
Nov 21 '18 at 17:51




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400494%2fproblems-with-inputs-w-spaces-in-a-batch-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)