0

I have windows batch file and also its scheduled in task scheduler.

task schedule working fine but the windows batch file does not execute

its in an php file. I am learning php and the windows batch file was coded previous employee.

The below code which i took from inside the windows batch file. The path is correct , what is the purpose of - f ? and can you correct me the code.

4
  • I hope there is a new line between @echo on and C:\php\... ? If not, this won´t work. And by the way: echo on is the default, so it does not make much sense to turn it on again. And normally you won`t care about what a scheduled task displays so it does not matter at all ;-) Commented Jun 29, 2015 at 13:35
  • Do you already know what is not being called ? It might help to add a short echo Successfully started %TIME% %DATE% >> C:\temp\task.log to the beginning of the file. This creates a short log when the batch was started Commented Jun 29, 2015 at 13:37
  • first line : @ECHO ON second line : C:\PHP5.3\php.exe -f "C:\www2\cron.php" Commented Jun 29, 2015 at 13:39
  • how can i test whether the above commands working or not. ? when i execute cron.php through the server, its working. the issue is windows batch file code. can you help on this Commented Jun 29, 2015 at 13:43

2 Answers 2

1

List of commandline options can be found here http://php.net/manual/en/features.commandline.options.php

in your case -f stands for Parse and execute File

Sign up to request clarification or add additional context in comments.

Comments

0

Change your batch to something like this:

@ECHO ON
echo Before php %TIME% %DATE% >> C:\temp\task.log
C:
Cd \www2
C:\PHP5.3\php.exe -f "C:\www2\cron.php" >> C:\temp\task.log
echo After php %TIME% %DATE% >> C:\temp\task.log

As long as you have the echo command and the call of the php interpreter on a single line this only output a meaningless text to the screen.

The first echo is there to help you diagnose problems: if the scheduled tasks is being called you will see this logged in task.log.

To make sure that the working directory is set to C:\www2 (cron.php will look for files there unless they get addressed with a full path) we change to that directory before running php.

In case php prints any error messages or information we redirect that output to the same log because otherwise you will not see this. You should delete that log from time to time because it can grow considerably. It is up to you to decide which of the logging statements you want to keep or remove ;-) You can even have the log roll over by size, I bet there are question here on SO that will show you how this can be done ;-)

8 Comments

i changed my batch file and seeing log file having records like... Successfully started 9:59:00.03 Mon 06/29/2015 Successfully started 10:00:00.15 Mon 06/29/2015 Successfully started 10:01:00.04 Mon 06/29/2015 Successfully started 10:02:00.04 Mon 06/29/2015 Successfully started 10:03:00.03 Mon 06/29/2015
Thats important information. So we can assume that the PHP script gets called. So there must be something inside PHP or the code. Post the code in your question so that we can have a look at it.
I posted my code, when i execute "cron.php" from sername/cron.php, its calling xml and working fine. can you guide me how to insert new sample code inside the php file and test it whether the cron.php is calling or not. ?
i know the code is complicated, guide me to create simple method inside the cron.php file and will to test whether the cron.php file executed or not. or let me know your suggestion.
@user3442289 I made some additions to the batch, please try again
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.