evi*_*ary 7 php windows batch-file
我需要在我的服务器上每晚午夜运行一个php脚本.在Linux系统上,我设置了一个cron作业,但我坚持使用Windows系统.
我知道我必须使用Windows任务调度程序设置一个任务,并且该任务需要运行.bat文件,而该文件又将运行php文件,但我不得不尝试编写.bat文件.
我现在拥有的是:
@echo off
REM this command runs the nightly cron job
start "C:\Program Files (x86)\PHP\v5.3\php.exe" -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试手动运行.bat文件进行测试时,我收到一个Windows警报说
"Windows无法找到'-f'.请确保正确输入名称,然后重试.
我错过了什么?
该START命令可选地接受所创建窗口的标题作为其第一个参数; 在这种情况下,它认为这C:\Program Files (x86)\PHP\v5.3\php.exe是要显示的标题,-f(第二个参数)是您要运行的可执行文件.
因此,您可以通过提供占位符标题来解决此问题,例如
start "email reminder task" "C:\Program Files (x86)\PHP\v5.3\php.exe" -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php
Run Code Online (Sandbox Code Playgroud)
或者,最好,你可以START完全抛弃命令(你没有使用它的任何独特功能),只需直接运行PHP:
"C:\Program Files (x86)\PHP\v5.3\php.exe" -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php
Run Code Online (Sandbox Code Playgroud)