Change current working directory from batch file a

2019-07-20 12:34发布

问题:

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 ?

回答1:

you might try this:

start "" /d "w:\folder" /b "p:\php\php.exe" file.php


回答2:

This may also work:

@echo off
cd /d "w:\folder"
"p:\php\php.exe" "file.php"


回答3:

this is how I solved the problem, try this:

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

this seems to work.