Unfitacorn
Unfitacorn

Reputation: 316

Running a php file in a batch file

I'm trying to run a php file within a batch file. I have the folder for php.exe within the same directory as the bat.

set addLocation="%cd%\test.php"
set exeLocation="%cd%\php\php.exe"

start "run" "%cd%\php\php.exe" "%location%"

pause

Any help would be appreciated

Upvotes: 0

Views: 2414

Answers (2)

Dilip Kumar
Dilip Kumar

Reputation: 11

You can follow the following code:

  1. To change the directory -

    set path = D:\Workspace
    CD /D %path%

  2. To run the php file -

    php file.php

This code will work well. Thank you.

Upvotes: 0

RiggsFolly
RiggsFolly

Reputation: 94672

I use this method myself

Batch file called xxxx.cmd

PATH=%PATH%;C:\path\to\folder\with\phpexe
CD \path\to\php_source
php file.php

The php folder is added to the PATH only for the duration of this command windows existance

Upvotes: 4

Related Questions