문제

@echo off
set /p Choice = Choose a number: 
echo %Choice%
pause>nul

I want to store my answer in a variable and print it out... Doesn't get any answer. What am i doing wrong?

도움이 되었습니까?

해결책

Remove the spaces around the = in your set command:

@echo off
set /p Choice=Choose a number: 
echo %Choice%
pause>nul

You may also notice that set doesn't put a space after your prompt, so with your code, it looks like this:

Choose a number:42
42

To fix this, enclose the prompt in double-quotes and put a space at the end:

set /p Choice="Choose a number: "

Output:

Choose a number: 42
42

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top