中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 17:20
47,812 topics / 349,917 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » If you get input variables in a batch processing
Printable Version  1,763 / 8
Floor1 PLATCH Posted 2003-03-19 00:00
初级用户 Posts 1 Credits 105
I want to make a batch processing to achieve that when running, it requires entering a string, and then turns to the corresponding branch according to this string. (It must be entered during running, and the form of adding parameters at the beginning cannot be used). How should I do it?

I started to want to use environment variables, and use a batch processing enhancement program INPUT to accept keyboard input, but it didn't work. My program is:
cls
input "Please Input:" FN /s rem: This sentence is to accept input and assign it to "FN"
if FN=="aaa" goto a
if FN=="bbb" goto b
goto c

:a
echo This is a
goto c

:b
echo this is b
goto c

:c
End!!!
Later, I found that the batch processing enhancement command INPUT didn't work.

Dear experts, please help.
Floor2 laoje Posted 2003-03-19 00:00
中级用户 Posts 36 Credits 223
You can consider using choice. It's very simple to use. Just type choice /? to see how to use it.
Floor3 willsort Posted 2003-03-27 00:00
元老会员 Posts 1,512 Credits 4,432
To PLATCH:

Running and accepting string variables is a major weakness of bat. If there are no other enhanced commands to help, simply relying on the internal and external commands that come with DOS to achieve this feature, the amount of code will be astonishing (I have tried it myself), and the value is not very great.

When I encounter such problems, I generally convert it into accepting string parameters from the command line, and then transfer to the corresponding subroutine site. This is not too difficult to implement:

:start
find ":%1" > nul
if errorlevel 0 goto error
goto %1

:proc1
......

:proc2
......

:error
echo Invalid argument!

:end

If you must implement this function, I can give you a suggestion. Throw out a DOS sub-SHELL from the main program with %comspec%, pass in the string disguised as the command line to the program, and then implement the subroutine as an independent bat program and call it directly. Maybe I didn't make it very clear. If you want to discuss this problem, contact me again!

Floor4 Wengier Posted 2003-03-27 00:00
系统支持 Posts 10,521 Credits 27,736
I tried, it's not that INPUT doesn't work, but that this batch program itself has serious bugs.

For example:
if FN=="aaa" goto a
if FN=="bbb" goto b

Should be changed to:

if "%FN%"=="aaa" goto a
if "%FN%"=="bbb" goto b
Floor5 neity Posted 2006-05-01 11:00
初级用户 Posts 9 Credits 21
Floor6 wang6610 Posted 2006-05-01 17:28
银牌会员 Posts 488 Credits 1,246
One more thing:

if "%FN%"=="bbb" goto b
How to represent the inequality sign in Chinese?
Floor7 220110 Posted 2006-05-01 22:58
荣誉版主 Posts 313 Credits 718
As far as I know, without using the inequality symbol notation like "!=" in C++ or "<>" in VB, we can only use:
if not "%FN%"== "bbb" goto b
Floor8 hxj Posted 2006-05-02 08:02
中级用户 Posts 66 Credits 377
If you only use the 26 letters (like drive letters) as input, you can use the following cumbersome method:

Choice /C:defghijklmnopqrstuvwxyz /n Please Input disk symbol
if errorlevel 23 set input=z
if errorlevel 23 goto z
if errorlevel 22 set input=y
if errorlevel 22 goto y
if errorlevel 21 set input=x
if errorlevel 21 goto x
if errorlevel 20 set input=w
if errorlevel 20 goto w
if errorlevel 19 set input=v
if errorlevel 19 goto v
if errorlevel 18 set input=u
if errorlevel 18 goto u
if errorlevel 17 set input=t
if errorlevel 17 goto t
if errorlevel 16 set input=s
if errorlevel 16 goto s
if errorlevel 15 set input=r
if errorlevel 15 goto r
if errorlevel 14 set input=q
if errorlevel 14 goto q
if errorlevel 13 set input=p
if errorlevel 13 goto p
if errorlevel 12 set input=o
if errorlevel 12 goto o
if errorlevel 11 set input=n
if errorlevel 11 goto n
if errorlevel 10 set input=m
if errorlevel 10 goto m
if errorlevel 9 set input=l
if errorlevel 9 goto l
if errorlevel 8 set input=k
if errorlevel 8 goto k
if errorlevel 7 set input=j
if errorlevel 7 goto j
if errorlevel 6 set input=i
if errorlevel 6 goto i
if errorlevel 5 set input=h
if errorlevel 5 goto h
if errorlevel 4 set input=g
if errorlevel 4 goto g
if errorlevel 3 set input=f
if errorlevel 3 goto f
if errorlevel 2 set input=e
if errorlevel 2 goto e
if errorlevel 1 set input=d
if errorlevel 1 goto d
Floor9 hxj Posted 2006-05-02 08:16
中级用户 Posts 66 Credits 377
Can set /p be used?

set /p input= Please input a "string"
if %input%=="aaa" goto a
if %input%=="bbb" goto b

[ Last edited by hxj on 2006-5-2 at 08:26 ]
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023