Skip to content

Instantly share code, notes, and snippets.

@sophiaphillipa
Last active February 18, 2017 17:50
Show Gist options
  • Save sophiaphillipa/fb59e1fc7cf9054fb7100a7e3ba0cdfb to your computer and use it in GitHub Desktop.
Save sophiaphillipa/fb59e1fc7cf9054fb7100a7e3ba0cdfb to your computer and use it in GitHub Desktop.
How to run outside applications on windows, using PHP
<?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');
}
}
@sophiaphillipa
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment