Pregunta

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!

¿Fue útil?

Solución

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

Otros consejos

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!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top