简体   繁体   English

如何从批处理文件执行PHP Codeigniter控制器

[英]How to execute php codeigniter controller from batch file

When I tried to run the script manually on the command line, working fine.The same code run in the batch file not working. 当我尝试在命令行上手动运行脚本时,可以正常工作。在批处理文件中运行的相同代码无法正常工作。 How to run the CodeIgniter controller in the batch file? 如何在批处理文件中运行CodeIgniter控制器?

file name : crone-job.bat 文件名:crone-job.bat

cd D:\www\Apache2.4\htdocs\reech\

D:\php7.0\php.exe index.php crone/recordCountStatus >D:\www\Apache2.4\htdocs\reech\result.txt

Error: Could not open input file: index.php 错误:无法打开输入文件:index.php

I dont think your case same like me, i hope this can be solve it, like my case : 我认为您的案件不像我一样,我希望这可以解决,就像我的案件一样:

  • Windows 10 Windows 10
  • PHP Version 5.6.23 PHP版本5.6.23
  • XAMPP v3.2.2 XAMPP v3.2.2

i have struture xampp installation like this - Drive E:\\folder1\\xampp\\htdocs\\currentworkspace (Root Codeigniter folder) 我有这样的结构xampp安装-驱动器E:\\ folder1 \\ xampp \\ htdocs \\ currentworkspace(Root Codeigniter文件夹)

And i create bat file like this 我创建这样的蝙蝠文件

@echo off
set "PATH=%PATH%;e:\folder1\xampp\htdocs\currentworkspace"
call e:
call cd folder1\xampp\htdocs\currentworkspace
:loop
call php index.php our_controller_name
PING 1.1.1.1 -n 3 -w 10000 >NUL
goto :loop

and save :) 并保存:)

" call e: " <<< because my default cmd always on drive C: “呼叫e:” <<<,因为我的默认cmd始终位于驱动器C:

PING 1.1.1.1 -n "3" <<< 3 second PING 1.1.1.1 -n“ 3” <<< 3秒

Sorry for bad english, but on my case it solve :D 对不起,英语不好,但是就我而言,它可以解决:D

Here is my working code, 这是我的工作代码,

Step 1: select the drive ' D ' or else 步骤1:选择驱动器' D '否则

Step 2: select the App location 步骤2:选择应用程序位置

Step 3: php location ' D:\\php\\php.exe ' or set in environment variables 步骤3:php位置' D:\\ php \\ php.exe '或在环境变量中设置

Step 4: index.php followed by controller_name/method_name ex: index.php crone/recordCountStatus 步骤4:index.php,后跟controller_name / method_name,例如: index.php crone / recordCountStatus

Step 5:save as .bat file and run this file in Task Scheduler 步骤5:另存为.bat文件并在Task Scheduler中运行此文件

D:
cd www\Apache2.4\htdocs\reech\
set LOGFILE_DATE=%DATE:~6,4%-%DATE:~3,3%-%DATE:~0,2%
set LOGFILE_TIME=%TIME:~0,2%-%TIME:~3,2%
set LOGFILE=%LOGFILE_DATE%-%LOGFILE_TIME%
D:\php\php.exe index.php crone/recordCountStatus  >>D:\www\Apache2.4\htdocs\reech\cron\log\dump-import-elasticsearch-log.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM