Issue
I want to run a batch file(say wanted to run calculator) on a specific date and time using python (but don't use the default scheduler). My program:
a = "C:\Windows\system32\calc.exe"
mybat = open(r"D:\Cyber_security\Python\cal.bat", "w+")
mybat.write(a)
mybat.close()
import datetime
start = datetime.datetime.now()
end = datetime.datetime(2022, 7, 12, 17, 29, 10)
while(True):
if(end - start == 0):
import subprocess
subprocess.call([r"D:\Cyber_security\Python\cal.bat"])
when I run it it doesn't show error but the batch file is not running at specific time. where is the wrong?
Solution
I already found my answer.
a = "C:\Windows\system32\calc.exe"
mybat = open(r"D:\Cyber_security\Python\cal.bat", "w+")
mybat.write(a)
mybat.close()
import sched
from datetime import datetime
import time
def action():
import subprocess
subprocess.call([r"D:\Cyber_security\Python\cal.bat"])
s = sched.scheduler(time.time, time.sleep)
e_x = s.enterabs(time.strptime('Tue Jul 12 19:57:17 2022'), 0, action)
s.run()
Answered By - ijahan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.