Windows Task Scheduler Last Run Result (0xF6) - python

What does Last Run Result (0xF6) mean?
I scheduled the Task Scheduler to run a *pythonw.exe with the arguments pointed to the *.py file.
User account is set for an admin account
Run whether user is logged on or not
Run with the highest privileges
Configured for Windows 10
I can't find a reference to this in a google search. Whatever is happening via the Task Scheduler I can't really tell because the python script does not finish-- meaning I can't read the log file to check how far it got or if it ran into any errors. If I run the script without the Task Scheduler it completes successfully.

Related

Scheduled Python script in task scheduler not working

I have a python script that I am trying to schedule to run in the task scheduler in my VM but it doesn't seem to be running, it returns (0x2) for last run result. I am able to run the script manually and it works. I even created a batch file to execute the script which works and tried scheduling that in Task Scheduler but it also gave the same error. My only guess is that it's not working because it uses the Google Sheets API and reads the credentials from a JSON file in the project folder but I'm still unsure as to why it wouldn't run when scheduled. If you have any ideas I would greatly appreciate it. In the task scheduler, I am using the path Z:\Python\PythonGSAPI\executePy.bat to execute the batch file. The content of the batch file is
#echo off
"C:\Python27\python.exe" "Z:\Python\PythonGSAPI\TF_Invoice.py"
pause
This occur due the PATH Enviroment variable, for exemple, if you use Anaconda Python it's needed to choose the first option during the installation or even configure this after.
enter image description here

Is it Possible to Run a Python Code Forever?

I have coded a Python Script for Twitter Automation using Tweepy. Now, when i run on my own Linux Machine as python file.py The file runs successfully and it keeps on running because i have specified repeated Tasks inside the Script and I also don't want to stop the script either. But as it is on my Local Machine, the script might get stopped when my Internet Connection is off or at Night. So i couldn't keep running the Script Whole day on my PC..
So is there any way or website or Method where i could deploy my Script and make it Execute forever there ? I have heard about CRON JOBS before in Cpanel which can Help repeated Tasks but here in my case i want to keep running my Script on the Machine till i don't close the script .
Are their any such solutions. Because most of twitter bots i see are running forever, meaning their Script is getting executed somewhere 24x7 . This is what i want to know, How is that Task possible?
As mentioned by Jon and Vincent, it's better to run the code from a cloud service. But either way, I think what you're looking for is what to put into the terminal to run the code even after you close the terminal. This is what worked for me:
nohup python code.py &
You can add a systemd .service file, which can have the added benefit of:
logging (compressed logs at a central place, or over network to a log server)
disallowing access to /tmp and /home-directories
restarting the service if it fails
starting the service at boot
setting capabilities (ref setcap/getcap), disallowing file access if the process only needs network access, for instance

Running python code as a service on windows server 2012 R2

I have a python script which collects data from Twitter and stores into MongoDb. I need to run this code on the server as a service.
However, only 2 users can remain logged into the server at any given time and therefore If I log out my account, the python script would stop working and data collection will stop.
My question is - How can I run this script as a service on the server such that it keeps running irrespective of whichever user is logged in?
Task Scheduler is the easiest solution I know of. You can use it to run the code at startup as the NT AUTHORITY\SYSTEM user and automatically restart on failure. In case you need it, there's a basic overview of Task Scheduler here.

Python Script Running in Windows Task Scheduler Completes with exit code 3221225477

I'm troubleshooting a python script that does 3 things.
Stops ArcGIS Server using subprocess.check_output('net stop "ArcGIS Server"', shell=True)
Runs some arcpy functions
Starts ArcGIS Server using subprocess.check_output('net start "ArcGIS Server"', shell=True)
The script runs fine when run from IDLE. It also runs fine as a scheduled task when I check the radio button that says "Run only when the user is logged on"
However, this task runs on a server and I don't want to have to be logged in for the task to run. So I check the radio button that says "Run whether user is logged on or not", and "Run with highest privileges".
The result is the script's log file is empty, and the script never completes. It returns the error code in the Task Scheduler, that I mentioned above.
More task details:
Action: Start a program
Program/script: C:\Python27\ArcGIS10.3\python.exe
Add arguments (optional): D:\ArcGISData\server-data\Python\copydata.py
Am I doing something wrong, or is there any other steps I can try to get this working?
Not sure why it wasn't working to be honest, but after going through the steps to recreate the task, it started working. Maybe I had just mistakenly entered the credentials of the user running the task or something like that.

Python script involving Outlook through win32com runs when double-clicking, but not through task scheduler

I have a python script that sends out an email using win32com and Outlook. The script runs without a hitch when I run it through an interpreter or double-click on the script. However, when I run it through the Task Scheduler, I get the following message:
"Something went wrong. We couldn't start your program. Please try starting it again. If it won't start, try repairing Office from 'Programs and Features' in the Control Panel."
I'm using Office 365, and Python 2.6. I've tried running the script through the scheduler after killing the Outlook process, but I ran into the same issue.
Office isn't designed to run as a service, and needs to be run interactively. You'll need to change your task configuration in Task Scheduler to run the task as the currently logged-in user, on the current user's desktop, with the current user's privileges.

Categories

Resources