Execute php script in a bat file: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
(Created page with "How to execute php script in a bat file == Case 1: execute the php script without passing parameters == <pre> c:\path\to\php.exe -f "c:\path\to\php_script.php" or c:\path\t...")
 
No edit summary
Line 1: Line 1:
How to execute php script in a bat file
How to execute php script in a bat file


== Case 1: execute the php script without passing parameters ==
== Case 1: Execute the PHP script without passing parameters ==
<pre>
<pre>
c:\path\to\php.exe -f "c:\path\to\php_script.php"
c:\path\to\php.exe -f "c:\path\to\php_script.php"
Line 10: Line 10:
</pre>
</pre>


== Case 2: execute the php script passing parameters ==
== Case 2: Execute the PHP script passing parameters ==
<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 21: Line 21:


Options "-f <file>        Parse and execute <file>."<ref>[http://php.net/manual/en/features.commandline.options.php PHP: Options - Manual]</ref>
Options "-f <file>        Parse and execute <file>."<ref>[http://php.net/manual/en/features.commandline.options.php PHP: Options - Manual]</ref>
== Application: Run the PHP script automatically at a specified time ==
* {{Gd}} {{Win}} Using [https://www.splinterware.com/products/scheduler.html System Scheduler] software & specify the path to bat file.
* {{Win}} Task Scheduler in Windows 10<ref>[https://windowsreport.com/schedule-tasks-windows-10/ How to schedule tasks in Windows 10]</ref> (Windows 系統管理工具 → 工作排程器<ref>[https://key.chtouch.com/ContentView.aspx?P=2487 如何利用 Windows 10 內建的工作排程器,設定電腦定時自動關機、休眠或自動重開機?]</ref>)
* {{Linux}} [https://en.wikipedia.org/wiki/Cron Cron]


== Troubleshootings ==
== Troubleshootings ==
Line 45: Line 50:
== Related articles ==
== Related articles ==
* [http://php.net/getopt PHP: getopt - Manual]
* [http://php.net/getopt PHP: getopt - Manual]
* [[Boot up Tasks]] / [[Boot up Tasks#自動執行程式 | 自動執行程式]]


[[Category:Programming]] [[Category:PHP]]
[[Category:Programming]] [[Category:PHP]]

Revision as of 10:46, 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

  • Good.gif Win Os windows.png Using System Scheduler software & specify the path to bat file.
  • Win Os windows.png Task Scheduler in Windows 10[2] (Windows 系統管理工具 → 工作排程器[3])
  • Linux Os linux.png 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

After:

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


References

Related articles