【发布时间】:2011-12-26 17:31:50
【问题描述】:
我正在编写一个远程重启/关闭 PC 的 pyQt 客户端-服务器应用程序。
receivers 正在监听网络以获取传入消息,sender 向选定的接收者发送重启/关闭消息。
以下部分代码在接收器上运行:
import os
self.currentOS = calling a function to determine the current OS
if self.currentOS == "Win":
os.system("shutdown -r -f -t 1")
elif self.currentOS == "Lin":
os.system("shutdown -r now")
我有 2 台虚拟机作为接收器,一台在 Windows 上,另一台在 Linux 上。
当我向 Windows 接收器发送重启消息时,机器会重启。
当我向 Linux 接收器发送重启消息时,它要求输入密码
Incoming:EXEC_OP_RESTART
[sudo] password for jwalker:
我必须改变什么来克服这个问题?shutdown -r now 是唯一的方法,还是我可以用另一种方法(更直接)?
编辑:
在this 问题中,使用了一种叫做dbus 的东西,而且它没有密码,我正在搜索dbus,作为替代。
【问题讨论】:
-
供参考,Linux和Windows都可以使用
shutdown -r -t 1。在 Windows 上,-t 1意味着-f,因此您不必指定该选项(这意味着在 Linux 上完全不同)。 -
@cHao 不正确。 Windows 中的
-f表示强制关机。不等于-t 1。见:microsoft.com/resources/documentation/windows/xp/all/proddocs/… -
@Shivan:我现在正在看
shutdown -?。它对 /t 明确表示,“如果超时期限 [-t] 大于 0,则隐含 /f 参数。”它也说对于/f,“当为/t参数指定大于0的值时,隐含了/f参数。”
标签: linux qt python-3.x pyqt dbus