The Automation Pipeline — Pairing with a Scheduler So It Works at Night Too
Description and use
Automating a Python script on Windows with Task Scheduler using a .vbs wrapper, UTF‑8 output, lock file, and state file to avoid duplicates and orphan processes.
Problem
Automating a Python script on Windows to run unattended without manual intervention, while avoiding common pitfalls such as console flashes, encoding errors, orphan processes, and silent failures.
Outcome
The pipeline runs unattended, produces artifacts, surfaces failures, avoids orphan processes, and prevents duplicate outputs.
Workflow
- 1. Create a .vbs wrapper that runs the Python script with no window and waits for completion.
2. Ensure the wrapper exits with the script’s return code using
WScript.Quit rc. 3. Use a launcherrun.pyto set UTF‑8 stdout and invoke the main script viasubprocess.run. 4. Verify the scheduler entry contains no Korean characters. 5. Implement a lock file (collect.lock) and afinallyblock to release it. 6. Add a state file (SEEN) to track processed items and avoid duplicates. 7. Test the task manually after registration and confirm the output artifact. 8. Check that failures (e.g., network disconnect) appear in the report. 9. Verify no orphan processes after several runs. 10. Schedule the task at a desired interval (daily recommended).
Evidence
If the scheduler runs python or a .bat directly, a black window pops up every few minutes and interrupts your work.
The proper approach is a wscript + .vbs wrapper.
If you leave this out, the script can fail every single day while the scheduler's history records success.
When unattended execution fails repeatedly, zombie processes pile up, and one day the whole computer slows down.
- Record date: 2026-09-15T16:02:02.191Z