Running script via task scheduler

136 views
Skip to first unread message

evgeny...@gmail.com

unread,
Apr 16, 2020, 5:40:52 AM4/16/20
to openpyxl-users
Hello! Openpyxl is very beautiful lib, but I found little trouble. I'm not sure if it's bug or not, but looks like, that scripts don't work if run them via task scheduler. I created script to parse XLSX file and tried running them on a server, but I found out that they executed with error 0xFF. If I try running them manually, everything is fine. Do anybody faced with this problem?

Charlie Clark

unread,
Apr 16, 2020, 5:49:07 AM4/16/20
to openpyxl-users
You'll need to make sure that the user the scheduler runs with has
access to a Python installation where openpyxl has been installed. I've
no idea how this done on Windows but as it's a fairly common problem I
suspect you'll find a good answer on StackOverflow.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

evgeny...@gmail.com

unread,
Apr 16, 2020, 6:13:48 AM4/16/20
to openpyxl-users
Thank you for your answer!

I checked access rights for Python installation folder. My user has R+W access rights. Even more, I tried usind user with admin rights, but it didn't help. I try to compile my code to EXE file using pyinstaller module, it packs necessary files into EXE, to allow running the script on PC without Python, but result is the same: it works if I run it manually, and don't if I run it via scheduler.

evgeny...@gmail.com

unread,
Apr 17, 2020, 4:49:00 AM4/17/20
to openpyxl-users
Looks like I found the solution. I asked this question in another community and they asked me to check file paths inside of my script and use only absolute paths. It works. I used path. I used os.path.dirname(path.realpath(__file__)) to get script directory and create absolute paths. After that I was able to use task scheduler.

TODOPORLABOLSA s

unread,
May 5, 2021, 4:11:00 PM5/5/21
to openpyxl-users
Hi evgeny, could you share me the code for the task scheduler. 

Best regard from spain. 

Evgeny Minikh

unread,
May 5, 2021, 4:19:31 PM5/5/21
to openpyxl-users
Hi! To get a full path to your script directory use this way:

from os import path
this_script_directory = path.dirname(path.realpath(__file__)) 
CONFIG_FILENAME = this_script_dir + '\\config.cfg'

File config.cfg is stored in the directory with the Python script. So, using this you'll get CONFIG_FILENAME with full path to your config.cfg file. Something like this: 'C:\Dev\MyApp\config.cfg'
After that it's possible to compile your code to exe and use it via task scheduler.

TODOPORLABOLSA s

unread,
May 6, 2021, 11:23:11 AM5/6/21
to openpyxl-users
Great, thank you for your time and material. 

Regrads. 

Reply all
Reply to author
Forward
0 new messages