Execute php script in a bat file: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| Line 35: | Line 35: | ||
</pre> | </pre> | ||
Solution: (1) add {{kbd | key=<nowiki>--</nowiki>}} after php script (2) remove {{kbd|key=<nowiki>-f</nowiki>}} option from command | |||
<pre> | <pre> | ||
c:\path\to\php.exe -f "c:\path\to\php_script.php" -- -var1=value1 | c:\path\to\php.exe -f "c:\path\to\php_script.php" -- -var1=value1 | ||
| Line 43: | Line 43: | ||
c:\path\to\php.exe "c:\path\to\php_script.php" -var1=value1 | c:\path\to\php.exe "c:\path\to\php_script.php" -var1=value1 | ||
</pre> | </pre> | ||
== References == | == References == | ||
Revision as of 10:48, 1 March 2018
How to execute php script in a bat file
Case 1: Execute the PHP script without passing parameters
c:\path\to\php.exe -f "c:\path\to\php_script.php" or c:\path\to\php.exe "c:\path\to\php_script.php"
Case 2: Execute the PHP script passing parameters
c:\path\to\php.exe -f "c:\path\to\php_script.php" -- -var1=value1 or c:\path\to\php.exe "c:\path\to\php_script.php" -var1=value1
Options "-f <file> Parse and execute <file>."[1]
Application: Run the PHP script automatically at a specified time
Win
Using System Scheduler software & specify the path to bat file.- Win
Task Scheduler in Windows 10[2] (Windows 系統管理工具 → 工作排程器[3]) - Linux
Cron
Troubleshootings
Error message[4]: Could not open input file
The code caused the error message:
c:\path\to\php.exe -f "c:\path\to\php_script.php" -var1=value1
Solution: (1) add -- after php script (2) remove -f option from command
c:\path\to\php.exe -f "c:\path\to\php_script.php" -- -var1=value1 or c:\path\to\php.exe "c:\path\to\php_script.php" -var1=value1