0

I'm looking for a way to accept user input for timeout in a batch file. Basically, when the batch program starts, the user will have the option to input a timeout in minutes which will be calculated into seconds and passed as a variable until the next step proceeded.

Unfortunately I couldn't find anything on the web ;(

@echo off
REM set timeout by using the input of the user
shutdown -f -s -t (here comes in user input * 60)

Would something like this be possible with CMD?

3
  • 1
    What exact strings did you search for? Because set /p will do what you want. Commented Feb 6, 2015 at 18:37
  • I did found set /p but I couldn't understand it. Commented Feb 6, 2015 at 18:51
  • The usage for set /p is set /p variable=prompt where prompt is what the script shows the user when it asks for input and variable is the variable that the input gets stored in. Commented Feb 6, 2015 at 19:26

2 Answers 2

2

There is actually a native TIMEOUT method for this:

set /p mtime="Enter time in minutes: "
set /a stime=%mtime%*60
timeout /t %stime%

Append /nobreak to ignore user key strokes. Otherwise if the user does press a key, execution will resume immediately.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for that @meatspace! Your approach as well works, but I'm familiar with the suggestion of @theglossy1 If I could I would mark the suggestion as correct answer!
1
set /p TIMEOUT="In how many minutes should the server shut down? "
set /a TIMEOUT = %TIMEOUT% * 60

This will set the TIMEOUT variable to whatever the user enters. As per your initial post, you could then call it with shutdown -f -s -t %TIMEOUT%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.