Execute php script in a bat file: Difference between revisions

Jump to navigation Jump to search
Line 23: Line 23:


== Sample bat file ==
== Sample bat file ==
Condition1: The DOS window was NOT closed when PHP script which implemented [http://php.net/manual/en/function.exit.php exit()] and returned error.
<pre>
@ECHO OFF
c:\path\to\php.exe "c:\path\to\php_script.php" -var1=value1
if NOT ["%errorlevel%"]==["0"] (
    PAUSE
    exit /b %errorlevel%
)
</pre>
Condition2: The DOS window was NOT closed automatically. It might annoying if there are too many window.
<pre>
<pre>
@ECHO OFF
@ECHO OFF
Line 33: Line 44:
* [https://www.computerhope.com/echohlp.htm MS-DOS echo command help]
* [https://www.computerhope.com/echohlp.htm MS-DOS echo command help]
* {{kbd | key=<nowiki>PAUSE</nowiki>}} at the end of file to prevent auto closing of console window after the execution of batch file. <ref>[https://www.computerhope.com/pausehlp.htm MS-DOS pause command help]</ref><ref>[https://stackoverflow.com/questions/988403/how-to-prevent-auto-closing-of-console-after-the-execution-of-batch-file windows - How to prevent auto-closing of console after the execution of batch file. - Stack Overflow]</ref>
* {{kbd | key=<nowiki>PAUSE</nowiki>}} at the end of file to prevent auto closing of console window after the execution of batch file. <ref>[https://www.computerhope.com/pausehlp.htm MS-DOS pause command help]</ref><ref>[https://stackoverflow.com/questions/988403/how-to-prevent-auto-closing-of-console-after-the-execution-of-batch-file windows - How to prevent auto-closing of console after the execution of batch file. - Stack Overflow]</ref>
* [https://coderwall.com/p/jexjlw/pause-on-error-in-batch-file Pause on error in Batch File (Example)]


== Application: Run the PHP script automatically at a specified time ==
== Application: Run the PHP script automatically at a specified time ==

Navigation menu