2

Desired Result

Hi, I am using a machine running windows 10 to automate a scraper that is written in python and uses selenium (with chrome driver). I want this to run every day at 3:00 am.

Best Attempt

It seems the best way to do this is to write a batch file test_bat.bat that runs the python script in its virtual environment. Here are the contents of test_bat.bat:

C:\Users\data_miner\PycharmProjects\SeleniumScraper\venv\Scripts\activate.bat && python C:\Users\data_miner\PycharmProjects\SeleniumScraper\ScraperWindows.py

I learned how to do this here. This works excellently when run by clicking on the .bat file icon directly.

Problem

However, when fired (whether by the trigger or manually) there is no effect other than a change of status from 'ready' to 'running' and the pictured rows in history:

enter image description here

Details

The Action that I created has the following values (instructions were followed from here):

Action: Start a program, Program/script: C:\data_miner\Desktop\test_batch.bat

("C:\data_miner\Desktop\test_batch.bat" is the path to the batch file)

A similar problem that I have read the solution for:

HERE: the solution to this problem was setting the "working directory" to the location of the bat file. I first assumed that by working directory, they meant the 'Start in (optional)' field in 'Actions', this didn't work. Secondly I tried adding a cd command to the first line of the batch file: cd C:\data_miner\Desktop this also made no difference.

Comments

I can provide the python scripts if appropriate but chose not to here as the script works fine when run from the bat. The problem is in the transition from opening the bat to getting task scheduler to open it.

How do I get this thing to work?

  • 3
    There is absolutely no need to try to squeeze two commands onto one line in a batch file, so start by putting each onto a new line. Then, you need to `Call` the `.bat` file on the first line. Line 1: `@Call "%UserProfile%\PycharmProjects\SeleniumScraper\venv\Scripts\activate.bat"`; Line 2: `@"%LocalAppData%\Programs\Python\Python39\python.exe" "C:\Users\data_miner\PycharmProjects\SeleniumScraper\ScraperWindows.py"`. Or Line 1: `@CD /D "C:\Users\data_miner\PycharmProjects\SeleniumScraper"` Line 2: "" – Compo Aug 18 '21 at 10:03
  • 1
    …, Or Line 1: `@CD /D "%UserProfile%\PycharmProjects\SeleniumScraper"`; Line 2: `@Call "venv\Scripts\activate.bat"`; Line 3: `@"%LocalAppData%\Programs\Python\Python39\python.exe" "ScraperWindows.py"`. However, if you are running this under highest privileges, or as another user, then you should not use the `%UserProfile%` or `%LocalAppData%` variables: Line 1: `@CD /D "%SystemDrive%\Users\data_miner\PycharmProjects\SeleniumScraper"`; Line 2: `@Call "venv\Scripts\activate.bat"`; Line 3: `@"%SystemDrive%\Users\data_miner\AppData\Local\Programs\Python\Python39\python.exe" "ScraperWindows.py"` – Compo Aug 18 '21 at 10:17
  • have read through and am in process of reading and trialing thank you for the detailed responses, I'll have specific feedback soon. – Jose_harkhan Aug 18 '21 at 11:05
  • adding the path to the script worked for me, thanks! – ssanga Oct 14 '22 at 06:41

0 Answers0