0

So my question is the following : How to programmatically scheduling cron in windows using the python-crontab module ? (basically a script.py would schedule tasks by itself)

Environnment : Windows 10

I have already searched through countless posts and articles and found what looked like a solution but I unfortunately seem to dumb to understand it ...

From the python-crontab documentation : https://pypi.org/project/python-crontab/

It says to run something like

tab = CronTab(tabfile='MyScripts.tab')
for result in tab.run_scheduler():
    print("This was printed to stdout by the process.")

Unfortunately this doesn't make any sense to me ... What is MyScripts.tab supposed to contain ? What is it even ? What is a .tab file ? What is this code doing ? How can I implement that to my script to reach my goal ?

Ultimately I aim to code a script that will schedule cron on both windows and linux ( linux is done ) without having to enter root or user password or whatever ...

So if somebody understand the code up there or how to execute what I'm trying to do THANK YOU !

eden annonay
  • 37
  • 1
  • 8
  • According to comments in [this question](https://stackoverflow.com/questions/48311909/scheduling-python-script-using-python-crontab-on-windows-7) it may not work for Windows. You better try [scheduler for humans](https://github.com/dbader/schedule) or my own [scripting platform](https://github.com/vikilpet/Taskopy) which is made specifically for Windows. – viilpe Nov 28 '20 at 19:10
  • Thanks ! But will the script run like a cron ? What I mean is will it run even if my main script is not running ? Because if I have to run a thread inside a while loop it kinda defeats the purpose unfortunately – eden annonay Nov 29 '20 at 03:17
  • if you don't want constantly running script, you better take a look at the Windows Scheduler. – viilpe Nov 29 '20 at 09:31
  • which is what I was doing I tried every tool to schedule in code but not a single one worked so I guess this question will stay unanswered – eden annonay Nov 29 '20 at 10:12
  • Then your question is totally wrong because there is no such thing as *cron* in Windows but there are [examples](https://stackoverflow.com/questions/26160900/is-there-a-way-to-add-a-task-to-the-windows-task-scheduler-via-python-3) how to control Task Scheduler via Python. – viilpe Nov 29 '20 at 10:25
  • Or maybe you can't read since I asked how to do it with the "python-crontab" module I did not say it had to be a cron like the linux crons I know it has to do with the task manager and fyi I read the post that you linked and it didn't worked I did the same with every module you can imagine.. nope it didn't work and even in pure command through os.system() it would still tell me that I don't have the admin rights and the goal is to run as user... So as I said my question, which is still valid, will remain unanswered :) – eden annonay Nov 29 '20 at 13:27

0 Answers0