0
votes

I have a script that I'd like to run daily and found a very helpful article on how to use the Windows Task Scheduler. As the tutorial instructed, I made a .bat file:

"C:\Python\python.exe" "C:\Python\mee6APIData\mee6DataGetter.py"
pause

and whenever I run this file, the resulting .csv file gets written properly. However, when the scheduler runs the same .bat file there is no file written. I do get a permission error as well as a traceback that might help:

Traceback (most recent call last):
    File "C:\Python\mee6APIData\mee6DataGetter.py", line 34, in <module>
        loop.run_until_complete(job())
    File "C:\Python\lib\asyncio\base_events.py", line 616, in run_until_complete
        return future.result()
    File "C:\Python\mee6APIData\mee6DataGetter.py", line 31, in job
        await readData(1)
    File "C:\Python\mee6APIData\mee6DataGetter.py", line 28, in readData
        np.savetxt(date + '.csv', initArray, delimiter=', ', comments='', fmt='%s', encoding='utf8')
    File "<__array_function__ internals>", line 5, in savetxt
    File "C:\Python\lib\site-packages\numpy\lib\npyio.py", line 1377, in savetxt
        open(fname, 'wt').close()
PermissionError: [Errno 13] Permission denied: '03-22-2020.csv'

but there are no permission errors when running the program manually. I did find a similar question asked already, but I have not gotten this method to work either. Is there something that I'm missing? Does the Task Scheduler need to run the .bat file as an administrator? Any help is appreciated!

edit:

As an example for my error, the following code (exampleCode.py, which is in a folder named 'mee6APIData') works properly when ran manually:

import numpy as np
dataArray = ['user_ID', 'server_name', 'server_xp', 'date']
np.savetxt('example.csv', dataArray, delimiter=', ', comments='', fmt='%s', encoding='utf8')

and the corresponding .bat file:

"C:\Python\python.exe" "C:\Python\mee6APIData\exampleCode.py"
pause

following the aforementioned tutorial, the error should reveal itself as using the task scheduler does not save the file.

1
Did you try with an absolute path for the result file? The task scheduler might not have the same working directory or mounted network drives etc. - schlenk
I'm not entirely sure why that works, but it did! Thank you very much - yetAnotherConnor

1 Answers

0
votes

np.savetxt() should have the save file written to the absolute path and not a working directory:

np.savetxt('C:\Python\mee6APIData\example.csv', dataArray, delimiter=', ', comments='', fmt='%s', encoding='utf8')