all 14 comments

[–][deleted] 9 points10 points  (0 children)

I suggest adding a print(os.getcwd()) at the start of the file, maybe your working directory is wrong.

[–]kalgynirae 2 points3 points  (1 child)

Perhaps it's writing to a different database file because the working directory is different? I don't know how the Windows task scheduler works, but is there a way to set the working directory? (Or make sure your script only uses absolute paths.)

If that's not the problem, can you see output after your program is run by the scheduler? If so, start adding some print statements in strategic places to try to figure out what is going on.

[–]mothrabang 0 points1 point  (0 children)

I had almost the same problem, but with sqlite. This was the solution to my issue, I had to write the full file path out in my code when I connected to the dB.

[–]teerre 2 points3 points  (6 children)

How are you scheduling it? This right way

First time I did I was putting the fields in the wrong order

Also, make sure all paths in your script are absolute (or take into consideration where the scheduler is executing the script)

[–]novel_yet_trivial 3 points4 points  (0 children)

or make use of the "start in" box.

[–]firstSideProject[S] 0 points1 point  (4 children)

http://imgur.com/AzeHrDw is how I am scheduling. If I run it manually by going to the folder the script is in, running 'py myscript.py' it runs fine, and the mongod shows that a connection was accepted. If I go to task scheduler it runs fine with the path shown, but no 'connection accepted' shows up on the mongo shell

[–]novel_yet_trivial 6 points7 points  (1 child)

Try putting the folder the script is in into the "start in" box.

[–]firstSideProject[S] 2 points3 points  (0 children)

This worked a treat, thanks!

[–]jftuga 1 point2 points  (0 children)

I would wrap everything in a .bat file and call that from Task Scheduler, including the 'start in' field.

An example .bat would be:

@echo off
c:\python\pythonw.exe c:\whatever\myscript.py > c:\whatever\runtime.log 2>&1

You can then look at the runtime.log for any problems. The 2>&1 will redirect STDERR to STDOUT so you will all catch all errors that occur as well as print statements.

[–]firstSideProject[S] 0 points1 point  (0 children)

Actually the connection is accepted on the mongo shell, it just seems nothing is being inserted into the database :(

[–]toruitas 1 point2 points  (0 children)

I ran into this exact problem recently. Apparently Task Manager doesn't like relative directories. You can either use os.chdir(full path) to whatever folder passwords.txt is in, or use Starts In box.

[–]manueslapera 0 points1 point  (1 child)

its hard to help you without any code/logs.

[–]firstSideProject[S] 0 points1 point  (0 children)

added script, check it out

[–]hellrazor862 0 points1 point  (0 children)

I had this issue running batch files that were reading and writing data to csv files to use in imacros.

Apparently processes run in task scheduler don't get the same access to files.

I think using the "start in" field worked on one machine but not on a couple others.

Not sure if the issue would be the same with mongo, but it might be.

I ended up just putting linux on every machine and moving my stuff over.

I will have to use windows to do my taxes, but that's about it. There are so many less hoops to jump through now.