如何从批处理文件中的控制台读取输入?我试图实现的是 C 语言中 Scanf 的功能。如何在批处理文件中执行同样的操作?
The code snippet in the linked proposed duplicate reads user input.
ECHO A current build of Test Harness exists. set /p delBuild=Delete preexisting build [y/n]?:
The user can type as many letters as they want, and it will go into the delBuild variable.
In addition to the existing answer it is possible to set a default option as follows:
echo off ECHO A current build of Test Harness exists. set delBuild=n set /p delBuild=Delete preexisting build [y/n] (default - %delBuild%)?:
This allows users to simply hit "Enter" if they want to enter the default.
If you're just quickly looking to keep a cmd instance open instead of exiting immediately, simply doing the following is enough
set /p asd="Hit enter to continue"
at the end of your script and it'll keep the window open.
Note that this'll set asd as an environment variable, and can be replaced with anything else.
asd