这是我到目前为止所做的
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])
如果有任何其他方法可以做到这一点,将不胜感激。
提前致谢!