2

In Windows 8: I have a php file which needs to be run from the scheduled tasks through .bat file. The PHP is located in: P:\php\php.exe The file to run is located in: W:\folder\file.php

my .bat file looks like this:

cmd /c p:\php\php.exe w:\folder\file.php

It does not run. When I open cmd and switch to the file folder and run it from there, the file executes properly.

i.e.: W:\folder> p:\php\php.exe w:\folder\file.php

I have to add something to the .bat file which navigates to this w:\folder and executes it in the same manner but I cannot figure out what. I tried other posts (replies) i.e.: How to change current working directory using a batch file

but it did not take any effect. Can anyone help me to write the correct command for the .bat file please ?

Community
  • 1
  • 1
Milan
  • 3,209
  • 1
  • 35
  • 46

3 Answers3

8

you might try this:

start "" /d "w:\folder" /b "p:\php\php.exe" file.php
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • ..thanks, I will try it the first thing in the morning and let u know. – Milan Sep 20 '13 at 04:27
  • Yes! this works. I've tried all kinds of variations an possibilities and this is the only syntax which actually works! Just for completeness, the system is WIN 8. – Milan Sep 20 '13 at 15:08
3

This may also work:

@echo off
cd /d "w:\folder"
"p:\php\php.exe" "file.php"
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • ..thanks for your reply. I've seen this response in another tread already and I am sure it is correct for all older Win systems. Thank you again. ~m – Milan Sep 20 '13 at 15:11
  • 1
    Did you try it? It's a syntax that will work on any Windows NT class system including Windows 8.1 – foxidrive Sep 20 '13 at 15:14
  • ..hi, you r right, your syntax is slightly different that the above mentioned post from the other tread. Since I can accept only one answer, I am voting your comment up. Thanks. – Milan Sep 20 '13 at 16:11
  • For the sake of curiosity, what does the */d* argument do? And when is it needed? – Mathias Lykkegaard Lorenzen Apr 20 '15 at 16:36
  • @MathiasLykkegaardLorenzen The `cd` command can change the working directory on any drive, and the `/d` switch changes the current drive to match the one you are changing the folder on. It can be used with every `CD` command - unless you are purposely changing the working directory on another drive without intending to be on that drive. – foxidrive Apr 22 '15 at 07:21
0

this is how I solved the problem, try this:

cd p:\php\
p:
php.exe w:\folder\file.php

this seems to work.

Brent
  • 51
  • 1
  • 8