【问题标题】:User input PC name inserted into Windows CMD shutdown command via Python通过 Python 将用户输入的 PC 名称插入到 Windows CMD 关机命令中
【发布时间】:2019-02-20 16:24:27
【问题描述】:

我正在寻找如何获得我在提示符下键入的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 命令。

【问题讨论】:

  • os.system('shutdown /r /f /t 0 /m %s' % pc_name)

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-07-12
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    相关资源
    最近更新 更多