Change current working directory from batch file and run script

19,139

Solution 1

you might try this:

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

Solution 2

This may also work:

@echo off
cd /d "w:\folder"
"p:\php\php.exe" "file.php"
Share:
19,139
Milan
Author by

Milan

I am an independent designer / programmer who can develop, market and publish under one roof. My services are tailored to small companies or individuals.

Updated on June 04, 2022

Comments

  • Milan
    Milan about 2 years

    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 ?