Re hzy:
As GOTOmsdos said, to achieve the requester's requirement with batch processing composed solely of basic DOS commands, a rather complex script needs to be written. Roy's example can be seen as such. Usually in such cases, what we need to do is resolve the contradiction and handle it flexibly rather than just stubbornly proceeding. In fact, Roy's example is of no other value except to make people surprised, amazed, and confused. Although I myself also like to make others surprised, amazed, and confused : )
Let's provide another flexible idea. Usually, in batch processing, to obtain a string, the simplest and most commonly used method is to use command-line parameters. We can display the help text when the user doesn't enter a parameter string and give the correct parameter usage; when an incorrect parameter string is entered, give an error prompt. It's not difficult to do this.
Or, if it's foreseen that the optional fields of the string are not very large, then we can use "single-choice":
echo 1. *.txt 2. *.tmp 3. *.exe
choice /c:123 /n
Alternatively, if you just want to obtain a string halfway through the batch processing run and it exists in an environment variable, then you need a tool: askenv.exe. The script tools of "New DOS Era" can be downloaded.
In addition, correct a small bug: "Enter 'string' through the screen"
The screen is an output device and cannot "enter" a string. Entering a string is usually the task of the keyboard.
※ Batchinger 致 Bat Fans:请访问
批处理编程的异类 ,欢迎交流与共享批处理编程心得!