China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 01:56
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » What methods are there for receiving user input in batch processing? View 724 Replies 3
Original Poster Posted 2007-04-20 03:20 ·  中国 广东 东莞 电信
中级用户
★★
Credits 294
Posts 135
Joined 2007-03-09 14:47
19-year member
UID 81212
Gender Male
Status Offline
In pure DOS mode, the following statements can't be used:
set /p confrim=yes or no?(y/n):
if %confirm% == y goto ..
if %confirm% == n goto..

That is, wait on the screen to get a variable entered by the user. I know I can use CHOOSE, but it's an external command. I'd like to know what other methods there are to achieve the function above.
Floor 2 Posted 2007-04-20 04:23 ·  中国 广东 东莞 电信
中级用户
★★
Credits 294
Posts 135
Joined 2007-03-09 14:47
19-year member
UID 81212
Gender Male
Status Offline
Floor 3 Posted 2007-04-20 05:32 ·  中国 广东 东莞 电信
中级用户
★★
Credits 294
Posts 135
Joined 2007-03-09 14:47
19-year member
UID 81212
Gender Male
Status Offline
No one answering?
Floor 4 Posted 2007-04-20 07:34 ·  中国 新疆 乌鲁木齐 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
set /p confrim=yes or no?(y/n):
if %confirm% == y goto ..
if %confirm% == n goto..

This can do it, but there is one problem: if the user enters some other character, then %confirm% is neither equal to Y nor equal to n. So add another bit of code:

:re
set /p confrim=yes or no?(y/n):
if /i %confirm% == y goto ..
if /i %confirm% == n goto..

if /i %confirm% neq y goto :re
if /i %confirm% neq n goto :re
Forum Jump: