Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3837
  • Last Modified:

how to use batch file to run php script

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.
0
rmartes
Asked:
rmartes
2 Solutions
 
HermaniCommented:
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.
0
 
Dave BaldwinFixer of ProblemsCommented:
@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.
0
 
rmartesAuthor Commented:
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now