通过Python将用户输入的PC名称插入Windows CMD关闭命令

时间:2019-02-20 16:24:27

标签: python python-3.x windows cmd os.system

我正在寻找如何获取在pc_name重新启动命令末尾插入的提示符下键入的os.system的信息?或者即使我走在正确的轨道上。参见以下示例。

import os

pc_name = input ('Please enter the PC name to reboot: ')

os.system('shutdown /r /f /t 0 /m  <need pc_name here> ')

只是不想每次都在CMD中连续输入整个shutdown命令。

1 个答案:

答案 0 :(得分:2)

您可以使用.format()进行字符串格式化。

例如os.system('shutdown /r /f /t 0 /m {}'.format(pc_name))