2013-09-30 46 views
3

我正在做一個小項目,以瞭解更多關於python 2.7。我做了一個關機定時器,我得到了所有的GUI設置,我只需要關閉Windows 8的命令.cmd命令是:shutdown/t xxx。如何使用計時器關閉窗口與python 2.7

我曾嘗試以下:

import subprocess 
time = 10 
subprocess.call(["shutdown.exe", "/t", "time"]) 


import os 
time = 10 
os.system("shutdown /t %s " %str(time)) 

兩個不工作。 任何幫助表示讚賞,我使用Windows 8,所以我認爲與Windows 7的解決方案是不同的。

感謝您的答案,這裏是關機定時器我做:

https://github.com/hamiltino/shutdownTimer

+0

每個會發生什麼 - 錯誤信息,堆棧跟蹤,是什麼? – martineau

+1

想通了,我需要添加/ s。 cmd使用彈出並隨着顯示的關機幫助菜單消失。 – HashTables

回答

3

的第一個參數subprocess.call應該是程序的參數(字符串)或單串序列。

嘗試以下操作:

import subprocess 
time = 10 
subprocess.call(["shutdown.exe", "/t", str(time)]) # replaced `time` with `str(time)` 
# OR subprocess.call([r"C:\Windows\system32\shutdown.exe", "/t", str(time)]) 
#  specified the absolute path of the shutdown.exe 
#  The path may vary according to the installation. 

import os 
time = 10 
os.system("shutdown /t %s " % time) 
# `str` is not required, so removed. 
+0

啊,謝謝你,我還需要補充/它的工作。 – HashTables