I am trying to schedule a task in task scheduler I have created a batch file as below
"C:\ProgramData\Anaconda3\python.exe"
"C:\helloo\mail.py"
pause
the above is the content of my batch file. When I run the batch file I am able to get the output. I am not facing any issue with the code which I am executing. But with task scheduler I am following the below steps
1.open task scheduler
2.create task -- provided the name of the task and description
clicked on run whether the user is logged in or not and run with highest privileges
3.in triggers -->new --> onetime --ok
4.Action --> new--> action :start a program --
program script: where I kept my batch file.
5.cliked on finish
6. I am able to find the task in task scheduler but it is not showing as running
I need assistance in Actions tab
I have added the Action tab as below
1.in program i have mentioned PowerShell.exe
2. in next space i have mentioned -f " the file which you want to execute click on the file and click shift+right click and select copy as path "
Related
I wrote a python script to automate content recordings in AdobePremiere Pro. It is supposed to be triggered by tasks created on Windows' Task Scheduler. But it is not working as intended.
It seems like the commands expected are not being sent for some reason.
This is the link to the repository containing all the logic tried to achieve the automation task:
https://github.com/rfabreu/AdobePremiere-Recording-Automation-Python
After writing the python scripts, the batch scripts were created to execute those python files.
Then on the Task Scheduler, tasks were created to run the required batch scripts.
Python script to start a recording:
import schedule
import time
from pynput import keyboard
def start_recording():
with keyboard.Press(keyboard.Key.g):
keyboard.press(keyboard.Key.g)
keyboard.release(keyboard.Key.g)
schedule.every().day.at("18:50").do(start_recording)
while True:
schedule.run_pending()
time.sleep(1)
Batch script to run the python scripts when triggered:
#echo off
cd [enter_dir_name]
set PYTHON_EXE=python
set SCRIPT_DIRECTORY=.
for %%f in (%SCRIPT_DIRECTORY%\*.py) do (
start /B /MIN %PYTHON_EXE% "%%f"
)
The expected result is that the script sends keyboard commands at a certain time:
So, considering that AdobePremiere Pro is open, the first script should send a key press command of the "g" key to start recording when triggered by the bat file.
Then, when triggered at a certain time another script should send the key press command of the "esc" key to stop recording.
The final step if for the third script to send a key press command of the "enter" key to save the recorded content.
After trying different things, including updating python on the pc, nothing happens.
When checking the Task Scheduler logs it seems like the task to run the bat file was executed successfully, but then the desired outcome did not reflect any effects on AdobePremiere Pro.
I have followed these steps to schedule python script using Task scheduler and using arguments option in task scheduler but not able to run the scripts:
1. Open the Task Scheduler by searching for it in the Start menu.
2. Click on the "Create Basic Task" option from the Actions panel on the right.
3. Enter a name and description for the task and click "Next".
4. Select the frequency at which you want the task to run and click "Next".
5. Select the "Start a program" option and click "Next".
6. In the "Program/script" field, enter the path to the Python interpreter (e.g. "C:\Python36\python.exe").
7. In the "Add arguments" field, enter the path to your Python script followed by any required arguments. For example: "C:\scripts\myscript.py arg1 arg2".
8. Click "Next" and then click "Finish" to create the task.
Python Script to be scheduled:
import sys
print('Hello_1')
a = sys.argv[1]
print(a)
print('Hello_2')
I am able to do it through Batch File method. But not when using Arguments field in the Task Schedule.
I wrote a script for create several models in abaqus and then run the jobs created using a simple python loop, but when running the script the programm runs all the jobs at the same time and the computer memory isn't enough so it aborts the jobs. I want to know how create a srcipt where the next job is submitted just after the first has ended.
It depends on how you are invoking Abaqus. If you are creating the Abaqus processes directly you can add the -interactive argument to your command so it doesn't run the solver in a background process and return immediately. For example:
abq2018 -j my_job_name -interactive
On the other hand, if you are using the Abaqus API and the Job object to create and run jobs you can use the waitForCompletion method to wait until a Job completes. Here is the excerpt from the Abaqus documentation:
waitForCompletion() This method interrupts the execution of
the script until the end of the analysis. If you call the
waitForCompletion method and the status member is neither SUBMITTED
nor RUNNING, Abaqus assumes the analysis has either completed or
aborted and returns immediately.
Here's a short example of how to create Job objects and use the waitForCompletion method:
from abaqus import *
# Create a Job from a Model definition
j1 = mdb.Job(name='my_job_name', model=mdb.models['my_model_name'])
# or create a Job from an existing input file
j2 = mdb.JobFromInputFile(name='my_job_name', inputFileName='my_job_name.inp')
# Submit the first job - this returns immediately
j1.submit()
# Now wait for the first job - this will block until the job completes
j1.waitForCompletion()
# Same process for the second Job
j2.submit()
j2.waitForCompletion()
I developed a Graphic User Interface to improve the queueing process of Abaqus analyses.
It's available on GitHub here.
Install:
1. Download or clone the package from GitHub.
2. Find the core.py file and edit the lines 31, 36, 37 and 38 according to your machine and your config.
3. Run it.
If you have any issues using it, please submit them on the GitHub repository.
I have a job that starts in crontab with root privilege. This job should display a popup message after a while. The job is in python and use MessageBox toolkit.
With roit, the job works and after 5 minutes, I see the messagebox.
The problem is that if I login as a user, I can see the job running in the tasks list but the popup does not work (probably since the display of the job is of the root and not the user).
I cant find the way to change this job to use the display of the current ligin user.
Is there a way to change this so the user will see the popup?
Thanks.
The MessageBox does not popup because the cron job run in an environment where the DISPLAY (environment variable) is not set. Instead of having cron run your python directly, you can make it run a simple wrapper around it:
#!/usr/bin/env bash
export DISPLAY=':0'
python /path/to/your/python/program.sh
Alternatively, if your confident it won't mess with other cron jobs, you can add DISPLAY=:0 as the first line of your crontab.
I wrote a simple "git pull" script to be run on a Windows Server:
import logging
import subprocess
# Initialize logging
logger = logging.getLogger('autopull')
logger.setLevel(logging.INFO)
log_file = logging.FileHandler('autopull.log')
log_file.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s:%(levelname)s:%(message)s")
log_file.setFormatter(formatter)
logger.addHandler(log_file)
# Main part
logger.info('Started')
try:
subprocess.check_output("C:\Program Files\Git\cmd\git pull")
logger.info('Pulled repo successfully')
except:
logger.exception("Pulled failed")
I used a logger because the scheduler always told me that it executes with exit code 0 and I wanted to double check whether it was the case.
When I call the script by hand, it is working fine and the logger writes in the autopull.log. However, when it is called by the scheduler, the logger writes nothing. The task runs with the "Run with highest privileges" and "Run whether user is logged or not".
Is there something I did wrong ?
Edit 1 : Added Scheduled Task parameters
General :
"Run whether user is logged on or not" and "Run with highest privileges".
Configure for : Windows Server 2012 R2
Triggers:
Trigger : One time
Details : At 12:30 PM on 6/26/2017 - After triggered, repeat every 1 hour indefinitely
Status : Enabled
Actions:
Action : Start a program
Details : D:\Anaconda3\python.exe D:\projects\foo\autopull.py
Conditions:
"Start the task only if the computer is on AC power" and "Stop if the computer switched to battery power".
Settings:
"Allow task to be run on demand" and "if the running task does not end when requested, force it to stop".
#Dr Mouse, try this. I was able to run your code (while logged off). FYI, I am running Anaconda on Windows as well.
Once in the Edit Action window (in your actions, that you showed above, click on the edit button), in the program/script, be sure that it is pointing to the actual instance of your Python (Anaconda).
Put double quotes around the Program/Script
"D:\Anaconda3\python.exe"
Do not copy and paste, type it in.
In the add arguments optional:
-u "D:\projects\foo\autopull.py"
In Start in (optional) add the folder location to the script without quotes:
D:\projects\foo
If the above doesn't work, for troubleshooting purposes:
Does it work when you click on run (which runs it immediately) in task scheduler (naturally while logged in)?
In task scheduler, did you look through the history of the task to see where the scheduler is failing?
EDIT: Thinking more about it, I remember there was some issue with running python directly using the "Run whether user is logged on or not".
If the above does not work, try this:
create batch file (.bat) and add this line in it:
D:\Anaconda3\python.exe D:\projects\foo\autopull.py %*
point the task scheduler to this batch file (instead of pointing it to the python script directly).