这就是我迄今为止所做的
import subprocess
import datetime
now = datetime.datetime.now()
now_plus_10 = now + datetime.timedelta(seconds = 10)
path=r"path_to_file"
subprocess.call(['SchTasks', '/Create','/SC', 'ONCE','/TN', 'test1','/TR', path,'/ST', now_plus_10])
subprocess.call(['SchTasks', '/Create','/SC', 'ONCE','/TN', 'test2','/TR', path,'/ST', now_plus_10])我一直在犯的错误是:
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'datetime.datetime' is not iterable如果我像这样直接使用时间,任务就会被成功地调度:
time="09:06"
subprocess.call(['SchTasks', '/Create','/SC', 'ONCE','/TN', 'test3','/TR', path,'/ST', time])如果有其他方法可以做到这一点,我们将不胜感激。
提前谢谢!
发布于 2013-11-13 06:01:34
needquote = (" " in arg) or ("\t" in arg) or not arg我相信arg是datetime.datetime类型的,您使用的是in操作符。in运算符仅适用于可以迭代的对象,例如列表、数据集、集合等。因此,您需要做的是使用strftime将arg转换为字符串。
发布于 2013-11-13 06:25:04
抱歉打扰你们了。我现在知道答案了
import subprocess
import time
currenttime = time.time()
new= time.strftime("%H:%M:%S", time.localtime(currenttime + 0.6* 60))
path=r"path_to_file"
subprocess.call(['SchTasks', '/Create','/SC', 'ONCE','/TN', 'test1','/TR', path,'/ST', new])
subprocess.call(['SchTasks', '/Create','/SC', 'ONCE','/TN', 'test2','/TR', path,'/ST', new])不管怎样,谢谢你的帮助!
https://stackoverflow.com/questions/19946396
复制相似问题