how to use batch file to run php script

Posted on 2012-08-14
Last Modified: 2012-08-14
Hi Experts,

I'm having a little problem getting a batch file to run a php script. I have xampp installed on my Win Server 2k3. Here is what my .bat file looks like:

C:\xampp\php\php.exe -f "C:\xampp\htdocs\mysite\index.php"

I have also tried:

"C:\xampp\php\php.exe C:\xampp\htdocs\intertel_data_import\index.php"

My php script is set to update a mysql database and write to a log file. I can tell the php script works when ran through a browser because the database is updated and the log file is modified.

When I double click on the .bat file to execute it, a command prompt window opens and quickly closes. When I checked the database/log file created by the php script, there are no changes.

Any suggestions?

Thanks in advance.
Question by:rmartes
    LVL 3

    Accepted Solution

    Don't have php installed but you might want to
    open the console window in the directory where the bat file is located.
    then execute the BAT file from the console and see what is returned on the console.
    LVL 82

    Assisted Solution

    by:Dave Baldwin
    @Hermani's suggestion is good.  Since the window will not stay open the way you're doing it thru the GUI, you will not see any error messages.  In addition, on one PHP installation I had to have a separate 'php.ini' file for command line operation because the first one for use with the web server, had functions that only worked with the web server and caused errors when used on the command line.

    Author Closing Comment

    Excellent suggestion. My php script looks for a file with the current date as the filename and I forgot to add the file, resulting in a path error (which showed up in the console). Fixed it and it worked. Thank you so much.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now