Last active
February 18, 2017 17:50
-
-
Save sophiaphillipa/fb59e1fc7cf9054fb7100a7e3ba0cdfb to your computer and use it in GitHub Desktop.
How to run outside applications on windows, using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Running App on Windows SO | |
* | |
* There is some dificult on running apps trought PHP inside windows SO. | |
* Here are two methods that can make it easy | |
* | |
* @author Michel Phillipe | |
* @version 1.0 | |
*/ | |
class runApp{ | |
/* | |
* Run app throw shedulling iterator_apply | |
* @param String Handle the path and file of the executable | |
* @return void | |
*/ | |
function runAppByShedulling($executable){ | |
shell_exec('SCHTASKS /F /Create /TN _notepad /TR "'.$executable.'" /SC DAILY /RU INTERACTIVE'); | |
shell_exec('SCHTASKS /RUN /TN "_notepad"'); | |
shell_exec('SCHTASKS /DELETE /TN "_notepad" /F'); | |
} | |
function runAppByBatch($executable) | |
{ | |
file_put_contents(getcwd() . '\\' .'runApp.bat', 'start /d "'. dirname($executable) .'" /b "" "'.$executable .'"'); | |
exec('runApp.bat'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The second should do better the job. It just put executable call inside a .bat file, something like a container, Also make executable call using start, cause it let SO change to executable path, before start it. Than all we have to do is ask for bat, using exec.