Problems running python script by windows task scheduler that does pscp

I had the same issue when trying to open an MS Access database on a Linux VM. Running the script at the Windows 7 command prompt worked but running it in Task Scheduler didn't. With Task Scheduler it would find the database and verify it existed but wouldn't return the tables within it.

The solution was to have Task Scheduler run cmd as the Program/Script with the arguments /c python C:\path\to\script.py (under Add arguments (optional)).

I can't tell you why this works but it solved my problem.


You can use the windows Task Scheduler, but make sure the "optional" field "Start In" is filled in.

In the Task Scheduler app, add an action that specifies your python file to run "doSomeWork" and fill in the Start in (optional) input with the directory that contains the file.. So for example if you have a python file in:

C:\pythonProject\doSomeWork.py

You would enter:

Program/Script: doSomeWork.py

Start in (optional): C:\pythonProject 

I'm having a similar issue. In testing I found that any type of call with subprocess stops the python script when run in task scheduler but works fine when run on the command line.

import subprocess

print('Start')
test = subprocess.check_output(["dir"], shell=True)
print('First call finished')

When run on command line this outputs:

Start
First call finished

When run from task scheduler the output is:

Start

In order to get the output from task scheduler I run the python script from a batch file as follows:

python test.py >> log.txt

I run the script through the batch file both on command line and through task scheduler.