Hi I have been struggling to have "set /p" to work correctly in a batchfile. Its purpose is to print a text and ask for user input from keyboard and store this is in a variable.
Here is my code
Code is showing the text and is waiting for input but whatever i type before hit ENTER adds no value to UsersChoice. echo input was %UserChoice% only shows "input was " and nothing more. Then the if/else will be evaluated to else in line 13 printing exit (when working it will simply just exit)
Why are there no input stored in UsersChoice ???
This is the shell output where I have entered "o" as my choice (seen after : ).
Best regards
Vidar (Z)
Here is my code
Code:
1 if not exist %MY_FILE% (
2 :CopyFile
3 echo copying
4 copy /y %MY_FILE% %NEW_DIRECTORY% >NUL ) else (
5 echo %MY_FILE% already exist
6 set UsersChoice=
7 set /P UsersChoice=Overwrite before continue, Continue with old, Abort? o/c/a:
8 echo input was %UsersChoice%
9 if "%UsersChoice%"=="o" (
10 echo overwrite
11 goto :CopyFile ) else if "%UsersChoice%"=="c" (
12 echo continue
13 goto :Continue ) else (
14 echo exit))
15
16 :Continue
Why are there no input stored in UsersChoice ???
This is the shell output where I have entered "o" as my choice (seen after : ).
Code:
Overwrite before continue, Continue with old, Abort? o/c/a:o
input was
exit
Vidar (Z)
Last edited:
My Computer
- OS
- win7 pro