Running CakePHP Shell Script
Asked Answered
W

4

5

I have created a shell script as follows

<?php

class EmailShell extends AppShell
{
    public function main()
    {
        $this->out('Hello world.');
    }
}

When i navigate to the Console folder in command line and type cake email i get the following error.

Error: Shell class EmailShell could not be found.
#0 C:\wamp\www\gitgrow\lib\Cake\Console\ShellDispatcher.php(167): ShellDispatche
r->_getShell('email')
#1 C:\wamp\www\gitgrow\lib\Cake\Console\ShellDispatcher.php(69): ShellDispatcher
->dispatch()
#2 C:\wamp\www\gitgrow\app\Console\cake.php(33): ShellDispatcher::run(Array)
#3 {main}
Whirlpool answered 19/7, 2012 at 7:32 Comment(1)
see more: #10672134Valrievalry
D
6

create a shell for use in the Console. For this example, we’ll create a simple Hello world shell. In you applications Console/Command directory create EmailShell.php. Put the following code inside it:

class EmailShell extends AppShell {
    public function main() {
        $this->out('Hello world.');
    }
}

Then run this command :

Console/cake email

or

cake email
Dimorph answered 19/7, 2012 at 8:24 Comment(2)
thanks it worked. now when running a cron job. any idea what command i need to run for this script ?Whirlpool
See my answer below, or is it not clear enough for you?Therefrom
A
2

Run it at C:\wamp\www\gitgrow\app\. It should work.

cd C:\wamp\www\gitgrow\app
Console\cake email
Avlona answered 19/7, 2012 at 8:27 Comment(1)
This worked but this is a totally unintuitive choice on the part of the Cake devs. I'm on Windows. It works when you're in the /app folder and you run Console\cake email. But if you are already in the Console folder and you run cake email it doesn't work. That's just ridiculous! Especially since they have you add the Console folder to the system path. ?!?Sward
N
1

If your shell class is in the right place, then it might be a problem that cake does not know where your app root is. You can specify this using the -app argument.

cake -app ../app email
Nicholasnichole answered 19/7, 2012 at 7:41 Comment(2)
i am running it inside the app/Console folder itselfWhirlpool
the path also has been set in the windows environmentWhirlpool
T
1

See the following link about how to run Cake shells in cron:

http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html

Your cron command basically calls cd into the app directory and the cake command to run the shell together.

Therefrom answered 17/9, 2013 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.