This is what i have done so far

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])

The error I keep getting is:

needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'datetime.datetime' is not iterable

If I use the time directly like this,the task is scheduled successfully:

time="09:06"
subprocess.call(['SchTasks', '/Create','/SC', 'ONCE','/TN', 'test3','/TR', path,'/ST', time])

If there is any other way to do this,it would be much appreciated.

Thanks in Advance!

有帮助吗?

解决方案

needquote = (" " in arg) or ("\t" in arg) or not arg

I believe arg is of type datetime.datetime and you are using in operator on it. in operator works only on objects which can be iterated, for example, lists, dicts, sets etc. So, what you need to do is, convert arg to string using strftime

其他提示

Sorry to bother you guys. I got the answer now

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])

Thanks for helping anyways!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top