1

The goal of my script is to get input from a user for how much time they want before shutdown and also the message they want to appear during the shutdown process. My problem is I cannot figure out exactly how to put the variables into the shutdown command and have it execute properly.

import os

time = (input("How much time till shutdown?"))

message = input("What is your shutdown message?")

shutdown = "shutdown /f /r /t", time "c", message

os.system(shutdown)
2
  • Is that the code? Commented Dec 1, 2016 at 2:04
  • Yes, that is the code. Commented Dec 1, 2016 at 2:15

1 Answer 1

1

You need to assemble (by concatenating) the string shutdown so that it matches exactly what you want, including the quote marks around the comments.

For this purpose it is good to use single quotes for the string literals used in the concatenation so that unescaped double quotes can be freely used inside the strings.

Something like:

time = input("How much time till shutdown? ")
message = input("What is your shutdown message? ")

shutdown = 'shutdown /f /r /t ' + time + ' /c "' + message +'"'

print(shutdown)

A typical run:

How much time till shutdown? 60
What is your shutdown message? Goodbye
shutdown /f /r /t 60 /c "Goodbye"
Sign up to request clarification or add additional context in comments.

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.