I've been trying to find out how to set a time limit on a "set /p" in Batch for like 30 minutes and still couldn't find out how..
set /p example=i want this code to exit if it passes 3 seconds after it activated and the user typed nothing.
11 Answer
The SET command is not well-adapted to this kind of use, and user Jeff Zeitlin has in a comment suggested another command that does do time-limit.
If you still want to use the SET command this requires two batch files, as follows:
- Delete a specific temporary file, start Batch two, wait for a time, then kill Batch two. If the temporary file now exists, then its value can be used.
- Wait for input and store it in this temporary file. If it's killed before getting that input, then the file will not exist.
For an example of such batch files, seethis answer, that even manages this with only one batch file that starts a second thread to itself.
1