I wonder if someone can help, I want to run a schedule task and I discovered that I can put a command line command in there, which is good.
What I need to happen is for a PHP file to run a bit like a cronjob.
The system I am using recommends I do the below but it's not working, now I believe it's due to the file being on E and not C, but I have no idea how to correct this, if anyone could give me some pointers that would be great.
"C:\Program Files (x86)\PHP\v5.3\php.exe E:\pathtofile\tasks\frequently.php -f"
System info is win 7
You've got your quote characters all fouled up, but there are separate entries for the various parts of the command in Task Scheduler.
Try this:
When creating the new task, set the Action: dropdown to Start a program.
In the Program/Script: entry, use
"C:\Program Files (x86)\PHP\v5.3\php.exe"
In the Add arguments (optional) entry use
"E:\pathtofile\tasks\frequently.php" -f
I believe what you want to know is how to schedule the php program to process a php file via command prompt (Note that the -f needs to come immediately after the php.exe:
schtasks /Create /tn MyJob /tr #"C:\Program Files (x86)\PHP\v5.3\php.exe -f E:\pathtofile\tasks\frequently.php" /sc onlogon
Related
I have installed the anaconda package and been running python notebooks and python scripts easily directly from console. I created a script and want it to run every day at particular time period but it did not work. So I created a simple test file to check what is wrong. This is my test file
print("enter the no to exit")
input()
When I run this program on command prompt it ask me for an input and then it exit.
I followed this tutorial to run this program daily using windows scheduler https://blogs.esri.com/esri/arcgis/2013/07/30/scheduling-a-scrip/
In action tab I wrote this
"C:\Anaconda3\python.exe"
And the argument as
"E:\test.py"
And when I run the task manually a black window pop up and automatically closed, I cannot figure out what is wrong. I see it say something like invalid directory. I don't know what am I doing wrong. Please help.
To run Python programs in Task Manager on Windows: In "Programs/Script" input path to python.exe In "Add Arguments"input script file name In "Additional Information" input path to location where file is saved
For example:
Path to Python: C:\Users\your_user_name\AppData\Local\Programs\Python\Python36-32\Python.exe
Script name ./script.py
Path to location where script is saved: C:/foldername/
Add the following command in beginning of the .bat file where all the configuration of python and python script written
CD /d %~dp0
In my case .bat file looks like
CD /d %~dp0
Call "C:\Python\Python37-32\python.exe" "D:\myProject\script.py"
pause
Have a look into this thread from stack overflow:
You can do it in the command line as follows:
schtasks /Create /SC HOURLY /TN PythonTask /TR "PATH_TO_PYTHON_EXE PATH_TO_PYTHON_SCRIPT"
That will create an hourly task called 'PythonTask'. You can replace HOURLY with DAILY, WEEKLY etc. PATH_TO_PYTHON_EXE will be something like: C:\python25\python.exe. Check out more examples by writing this in the command line:
schtasks /?
Otherwise you can open the Task Scheduler and do it through the GUI. Hope this helps.
This might solve your problem.
If it is still not working you may refer to this thread from esri.
This will get your job done.
So I tried and tried but couldn't figure out this one for some reason.
how can I run a task from a desired directory instead of System32 directory where cmd.exe is.
so, when I schedule a task and try to run it ..
command prompt suppose to go to "c:\users\aaa\bbb\ccc" and then pass the argument.
Instead, It's starts at c:\Windows\System32 and fails.
Could anybody help me with this please?
I really appreciate it.
Thank you.
EDIT --
so, now I have a run.bat file with following content in it ...
C:\Users\aaa\bbb\ccc\dd (location to my testrunner.bat file)
testrunner.bat Scripts/all.suite website-address ie (command for the task I wanna perform)
net stop schedule (since window is poping up and going away way to fast, I added this to stop it (not working))
type run.bat
#echo off
cd C:\Users\aaa\bbb\ccc\dd
rem this will show all files in dir
rem is the file you're expecting listed?
dir
rem notice how you can make comments with a leading rem(ark)
#echo starting scripts\all.suite
rem you have to change this to have the full path using Windows X:\dir\dir conventions
c:\home\Scripts\all.suite website-address
#echo done running scripts\all.suite website-address
#echo shutting down
net stop schedule
So its still not clear exactly to me your goal. The reason I added the cd c:\... command is that will **C**hange **D**irectory to the path specified.
This is what you need so you can "run a task from a desired directory instead of System32".
Copy everything from the first #echo off to the last net stop and using notepad, paste it into a file, fix command names and paths website-urls, etc, then save that file to c:\temp\testrunner.bat.
Open a cmd.exe window and test that the script works. Just paste c:\temp\testrunner.bat on to cmd-line and hit enter. If that works, then made an entry in the scheduler to run c:\temp\testrunner.bat . I don't know the specifics of running a script for scheduler, so look for clues on the input screen. Is the an option to run 'now'?
If the .bat file doesn't work from the command-line, then you have to fix the file before you try running it in the scheduler. As your command Scripts/all.suite website-address is a little vague, you'll do better to post a new question asking for help to fix the .bat file and use a sample command that people will be able to use on their PCs at home.
IHTH.
Run a batch file from Task Scheduler is not working with a java command inside the .bat file. If I run the .bat file manually its working good.
Here is the simple .bat file I'm trying to schedule
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_24;
set CMD= "%JAVA_HOME%\bin\java" -version
echo %CMD%
%CMD%
When you type batchfile.bat on the command line, you are telling cmd.exe to read the file and execute each line it finds in it. When you double-click on your batch file in explorer, it calls cmd.exe for you, after reading the file associations in the registry.
Task Manager is not so kind.
So for your task to work, schedule it like this (from memory, not on a Windows box right now) :
cmd /c "c:\full\path\to\your\batchfile.bat"
For extra robustness, you could make sure you batch file run from a known directory, like the one that it reside in, by adding this at the top:
pushd %~dp0
REM .... The original batch file goes here ....
popd
And finally you could disable CMD autorun entry by adding /d right after cmd like this:
cmd /d /c "c:\full\path\to\your\batchfile.bat"
If ixe013's suggestion doesnt work go to
'Actions'
'Edit' the task
'Start in (optional):' Put the path to the directory where the script is
So for the last one if you have 'C:\Users\Desktop\script.py' just put in 'C:\Users\Desktop\' in the 'Start in (optional):' field
What worked for me was running the task as "Users" ( computername\Users ). Once I did that, and "run with highest privileges" checked, it ran without a hitch.
Giving the full path of java.exe in the batch file fixed it for me. In a notepad, I typed the following line:
"C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" -jar "C:\Users\usernameXXXX\Documents\NetBeansProjects\JavaApplication5\dist\JavaApplication5.jar"
Save this as a app1.bat file (C:\temp\app1.bat)
In the Actions tab of the task scheduler, give the path to the batch file, i.e, C:\temp\app1.bat
Also, be careful in the Conditions tab of task scheduler- make sure you uncheck "Start the task only if the computer is on AC power"
All other ways did not work for me, I followed this guide:
http://richardstk.com/2012/06/15/scheduled-task-to-run-a-batch-file/#comment-6873
In order to get the batch file to run, I had to set the "Program\script" box to contain just the name of the script (ie. script.bat) and set the the folder path of the script in the "Start in (optional)" box
I gave full permission to user Everyone from security tab from Properties of the folder in which batch file is. and it started working.
What a coworker discovered on something he had that wasn't working, and I have verified on the system I had that wasn't working is the following:
When the whole task is initially setup, you HAVE TO initially use the radio button "Run only when user is logged on". It will ask for your password for the change.
Now run the task.
Verify that whatever the batch was supposed to do, did happen.
And THEN change to the radio button BACK TO 'Run whether user is logged on or not."
This solved a problem for both of us that we had individually been working on for hours.
Side notes: both issues were also trying to elicit a 3rd party FTP app (WinSCP and WinFTP respectively) in each of our cases. Regular "inhouse" batch/tasks were having no issues.
I had the same problem, and to solve it, I put the next command line into the batch file:
cd "CURRENT_DIRECTORY"
where CURRENT_DIRECTORY is the directory where the batch file is located.
Example:
Suppose i have my batch file named test.bat located into c:\windows\system32\mytest
in my test.bat file, i introduce the next command line:
cd c:\windows\system32\mytest
I have created a Windows 7 scheduled task:
schtasks /create /tn MyTask /tr C:\temp\test\MyScript.bat /sc MINUTE
Problem is that this task seems to get executed by Windows but I think it can not find the running BAT script. There is a quick flash window but can't read what the problem is.
On the other hand, if I place the script under Windows/System32 everything works fine.
schtasks /create /tn MyTask /tr C:\windows\system32\MyScript.bat /sc MINUTE
Anyone knows why the second schedule task works compared to the first one?
This whole thing is part of installing a program on a windows machine from a web page. So I would like to have the BAT file installed in its correct directory and not the System32.
Thanks for you help.
C:\temp is a temporary directory may be cleaned by the OS periodically. So you should first check to make sure that batch file is actually there, and then consider moving it to a more permanent location.
Second, have you tried running the task manually from its intended location? That should help you see what the output is. You can also add PAUSE to the bottom of the batch file (as suggested by commenters) to ensure that it stays up long enough for you to see the output.
Some likely problems are:
You're using some resource which is in %windir% via a relative path, which won't work when the batch file is run from a different location.
The scheduled task is running as a different user and doesn't have the proper permissions.
The task is doing something that requires elevation, but the task itself is not set to run elevated.
IIRC, schtasks does not load user profile: Most probably a variable is not set that you need.
Try to prepend your command line (after /tr) with cmd /K. It will make the console kept alive.
HTH
I'm rolling out a new python script at the office and to make this run smooth I also made a batch file which will install it, and make it run on user logon.
I use schtasks.exe to schedule a task for this, so here is what i'm trying to run
schtasks /create /TN "fooname" /SC ONLOGON /TR "C:\foo - bar\fooscript.exe" /Delay 0005:00
The error I get is 0x80070002 which means the file cannot be found. After exporting the task I created, I can see that it separated the first and last bit of the path into
<Command>C:\foo</Command>
<Arguments>bar\fooscript.exe</Arguments>
I have tried microsofts own help article, but no luck. I wish to run this without any arguments regarding fooscript.exe.
As Magoo pointed out I was able to use the short name of the folder, which can be accessed with a
dir /x
tossing back a name like "FOO~1". Using this in my path made it work.
Thank you!
Sorry old thread but just found a workaround better than these here. Put the dir name in a prompt variable and then use the var in the command.
SET fname="c:\path with spaces\target.exe"
SchTasks [args] /TR %fname%