Issues launching a python script with Windows 7 Task Scheduler - python

I have a python script that incorporates subprocesses. I want it to run at a given time, so I set up a task to launch the .py script. However, it does not run...I viewed the history of the event and it appears to have "started" and closed all at 3:30:00 pm. So nothing really ever happened. I have also tried starting it in a batch file, that does not work with the task scheduler either. However, both the standalone script and the batch file work independently of the task scheduler just fine. Has anyone seen this or have any idea what I need to do to fix this issue?

Related

Automation of Powershell script, that invokes a Python script, doesn't work (via Task Scheduler)

I am trying to create a bunch of automations on my PC with Windows, and I encountered some obstacles while trying to automate a Powershell script with Windows Task Scheduler.
Right now, I have managed to set up a Task Scheduler to perform an actual script, but despite the whole script working as intended when I start it manually, it doesn't work right while invoked via task scheduler.
The Powershell script is very simple, it is meant to invoke a certain Python script. I also created a log transcript for testing purposes.
python dataset_creator.py --to_import yes --to_export yes
Start-Transcript -Path "<path>\transcript0.txt"
While invoked manually, the Python script works, but via Task Scheduler, the only working part is a transcript creation (ergo - no Python script is running). The Task Scheduler informs me itself that the task executed properly. This is how I set up the action:
Program: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "C:\<path>\powershell_script.ps1"
As for now, I have set it on a SYSTEM account, I have tried to set it on my user admin account, but it doesn't work as well.
Could you suggest the potential issues? I scrolled through several articles and nothing works. I also tried to skip the Powershell part (aka - set up the task relying only on a Python task), but it didn't work so far, and I also initially wanted to insert a number of Python scripts invokations into a single Powershell file.
I am also open to some Windows Task Scheduler alternatives suggestions.

Task Scheduler runs python.exe script but not pythonw.exe

Tried to schedule the launch of a script with the help of Task Scheduler so it runs daily / every 5 minutes. I'm out of solutions as to why my script seems to run fine when setting it up with python.exe but doesn't with pythonw.exe (silent).
I get this error code
Task Scheduler successfully completed task "\Automation\New Ads" , instance "{#######}" , action "C:\Users\#####\AppData\Local\Programs\Python\Python39\pythonw.exe" with return code 2147942401.
I've got no idea and can't seem to find a solution online.
Having a terminal pop every 5 minutes is annoying. That's the reason I'm looking at running it with pythonw.exe.

Console window closes abruptly while using windows task schedular to run Python script

I have written some Python code to automate a task. Then I scheduled the Python script to execute twice a week using windows task scheduler. The task runs but there are two issues.
The console prints some error. It is strange because when I run the script manually after opening command prompt everything works as expected. This is what I do manually.
cd directory
directory>script.py
Inside the task scheduler I have directly specified the location of the script to run as C:\full\path\to\script.py
Second issue is that I can't even diagnose the error because the console closes as soon as it executes the script. This is despite the fact that I have added a dummy input command at the end of script like this:
All my Python code
input('Press any key to exit')
I also tried to keep the console open by using time.sleep(60) after importing the time module.
Can anyone tell me how can I keep the console open. Let me repeat that I am running the script using windows task scheduler. Running the script manually generates no error.
Thanks.

Windows Task Scheduler running Python script: how to prevent taskeng.exe pop-up?

Windows 7 Task Scheduler is running my Python script every 15 minutes. Command line is something like c:\Python\python.exe c:\mypath\myscript.py. It all works well, script is called every 15 minues, etc.
However, the task scheduler pops up a huge console window titled taskeng.exe every time, blocking the view for a few seconds until the script exits.
Is there a way to prevent the pop-up?
Simply save your script with .pyw extension.
As far as I know, .pyw extension is the same as .py, only difference is that .pyw was implemented for GUI programs and therefore console window is not opened.
If there is more to it than this I wouldn't know, perhaps somebody more informed can edit this post or provide their own answer.
This helps me:
In the “General” tab, under the “Security options” section, select the Run whether user is logged on or not option. (This is the option that will make the command window not to appear when the task runs automatically.)
Clear the Do not store password option. (This is an optional step, but if the task isn’t working, check this option and supply the appropriate credentials to run the task.)

python script via windows 7 scheduler still running

I'm a noobie to python and have over the past few days tested and created a .PY file that runs perfectly from the command prompt either with the D:\Python34 or just as
Its pretty basic. Gets info from web and places it in a spreadsheet - I import requests, BeautifulSoup and openpyxl. The last statement is to save the workbook. I'm figuring that Python closes itself as does the workbook.
I wish to run it daily. So I used the Windows Task Scheduler on my Windows 7 Ultimate. I have it running only when I am logged in.
I have tried the following:
1) using python directly with complete paths
2) using only the full path and the
3) using a batch file that does #1 above and has an EXIT
4) using a batch file that does #2 above and has an EXIT
When running the batch from the command file OR Task Scheduler, the command window opens, it does its thing and the command window closes.
The problem is when I run it via the Task Scheduler in any of the above ways, it does its thing, but continues to say "RUNNING" in the scheduler.
I have tried to run the Windows Process Monitor using some filters I found on the web, however nothing shows up.
Extremely frustrating --Any suggestions would be appreciated.
Jerry
While I had the Task Scheduler open, the screen was showing "running". After I closed the screen and let it run the next day, everything worked fine. It must be something to do with the refresh on the task scheduler.
So my solution was to close the Task Scheduler and let it run as scheduled.

Categories