Reputation: 11830
I have an application that I have written in a very MVC fashion using Cake PHP. I now need to execute a shell script from within the application. Does Cake PHP provide a way of executing shell scripts? I.e. is there anything built in to do this or not? I am using CakePHP 2.
Many thanks :).
Upvotes: 0
Views: 4933
Reputation: 21743
yes, you can easily execute shell scripts manually from within your application. in 2.x this is even easier than in 1.3 etc:
App::uses('MyShell', 'Console/Command');
$this->My = new MyShell();
$this->My->myMethod();
I use it to test the shells I write inside the test cases. But it would also work within the app :)
Similar with Tasks. I use that in my TranslatePlugin to execute the ExtractTask of the core with some specific settings directly from the controller/model level.
Be aware that you might have to add/pass some manual ConsoleOutput class if you have some specific shell script. It would be better to move your code to a Task (not a shell!) if possible. Even better, move it inside a Lib or some other generic file you can dispatch from both your shell and your normal app code. This would be the cleanest approach on this subject.
Upvotes: 10
Reputation: 34877
Not directly, no. Shell script are -as the name suggests- meant to be run from a shell and not from within your app.
Although, there are some pointers how you can make your app interact with your shells in deizel's answer to this question.
Upvotes: 0