note 81543 deleted from function.exec by cmb
| From: | cmb@php.net | Date: | Sun, 24 Nov 2019 08:41:29 +0000 |
| Subject: | note 81543 deleted from function.exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213197@lists.php.net to get a copy of this message | ||
Note Submitter: jim dot filter at gmail dot com
----
You can embed php into a batch file so that it is essentially "double-click" to run. This
might be useful for script that does search and replace in numerous files or other tedious task that
are too complex for batch files but don't warrant greater attention. Its really quite simple
I'm sure someone has thought of it before. You can add whatever batch code you want after
:START just make sure you exit before you get to */ so Windows doesn't fuss. @php %0 basically
is saying "Open this file with php and run its php code". Obviously its really only a
useful trick on Windows, I only really use it for update scripts on our company's servers. I
suppose you could also just set Windows to open php files with php.exe but that seems like a rather
stupid thing to do as you would most often want to edit php files, not run them directly. @pause is
optional of course, but you may want to look at what php outputted to the command line before it
exits.
example.bat:
@GOTO START
<?php
...php code...
/*
:START
...batch code...
@php %0
@pause
@exit
*/
?>