python操作系统强制计算机重新启动用户输入的延迟时间应为多长

2024-10-03 15:30:02 发布

您现在位置:Python中文网/ 问答频道 /正文

import os
time = int(input("How many seconds do you want to delay restart?"))
chkdsk = "chkdsk /f C:"
restart = "shutdown -r -t ????" ####My problem is right here, how do i get
#the time input into that command
canrestart = "shutdown -a"
os.system(chkdsk)
os.system(restart)
print("Press enter key to cancel restart")
input()
os.system(canrestart)

我把我的问题放在了代码中,我问我如何接受用户的输入,然后把它放到重新启动命令中。在

从评论中,我能够让restart = "shutdown -r -t %d"% time工作


Tags: toimportinputtimeossystemdomany
1条回答
网友
1楼 · 发布于 2024-10-03 15:30:02

你试过了吗

restart = 'shutdown -r -t %d' % time

是吗?在

另外,原始输入通常比输入更安全。input()将计算用户键入的任何内容。在

相关问题 更多 >