Schedule a Python script via batch on windows (using Anaconda)

后端 未结 4 1722
别跟我提以往
别跟我提以往 2020-12-09 04:29

I have a script that i run every day and want to make a schedule for it, i have already tried a batch file with:

start C:\\Users\\name\\Miniconda3\\python.exe

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 04:59

    I would be a bit careful in calling python directly through environment as one never knows if the internals for activate function has changed.

    I'm just using basic bat-script to help me out.

    SET log_file=%cd%\logfile.txt
    call C:\Anaconda3\Scripts\activate.bat
    cd \script_directory
    python script.py arg1 arg2 > %log_file%
    

    This script saves the log-file wherever the bat is run from, calls the right environment through activate (in this case the standard) and directs all the stdout into log-file for further investigation.

    Then just point your Windows Task Scheduler to the script and set the home directory where you want the log-file to appear.

提交回复
热议问题