0

It appears to be '\' at the Task Sceduler GUI. and I used the command and I want the script to open files in the same path without using absolute path.

I scheduled the task using the command:

schtasks /Create /SC HOURLY /TN PythonTask /TR "PATH_TO_PYTHON_EXE PATH_TO_PYTHON_SCRIPT" 

and the script doesn't open a database on the same folder to which Glen wrote the answer for it at Schedule Python Script - Windows 7

Community
  • 1
  • 1
Alexander Suraphel
  • 10,103
  • 10
  • 55
  • 90

2 Answers2

2

I think it is better to wrap calling Python script into batch .bat file. In that file you can change directory, set PYTHONPATH etc

Such batch is then executed via:

schtasks /Create /SC HOURLY /TN PythonTask /TR "my_scheduled_task.bat"

In my_scheduled_task.bat you can call your Python script in any directory you want.

Such batch can be like:

c:
cd \my\dest\dir
c:\python32\python.exe c:\my\superscripts\dbsynchronizator.py
Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
  • I scheduled the task using the command: schtasks /Create /SC HOURLY /TN PythonTask /TR "PATH_TO_PYTHON_EXE PATH_TO_PYTHON_SCRIPT" and the script doesn't open a database on the same folder to which Glen wrote the answer for it at http://stackoverflow.com/questions/2725754/schedule-python-script-windows-7 . Can you tell me how to accomplish that. I don't have enough reps to comment on his answer. – Alexander Suraphel Apr 19 '12 at 12:16
0

os.chdir(path): "Change the current working directory to the specified path."

Walter
  • 7,809
  • 1
  • 30
  • 30