user3442289
user3442289

Reputation: 53

How to execute php file from windows batch file

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.

Upvotes: 0

Views: 2330

Answers (2)

Marged
Marged

Reputation: 10953

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 ;-)

Upvotes: 0

donald123
donald123

Reputation: 5739

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

Upvotes: 1

Related Questions