Passing Extra (Non Command-Line) Arguments To Console App

Hi,

This is my shell script invoked by another process:


exec &>> $LOG_FILE /usr/bin/php5 /home/username/console.php ConsoleProcess argument1

Now ‘console.php’ invokes Yii using:


Yii::createConsoleApplication($config)->run();

Fine, presuming ‘ConsoleProcessCommand.php’ is:


class ConsoleProcessCommand extends CConsoleCommand

{

    public function run($args)

    {

        echo "\r\n";

        print_r($args);

        echo "\r\n";

    }


}

I can see the output in the LOG_FILE:


Array

(

    [0] => argument1

)

This is all as expected - fine. But now I would like to pass another argument but not from shell but a PHP script running out of the Yii application scope. Basically, I would like to use something like (‘ConsoleProcessCommand.php’):


Yii::createConsoleApplication($config)->run('argument2');

and consequently, I would like to see the result like (LOG_FILE):


Array

(

    [0] => argument1

    [1] => argument2

)

So, the question is - how to run Yii console application form another PHP script (running in pipe) and pass a PHP variable to the application started this way???

(the reason for that is to avoid Yii overhead prior specialized PHP script checks other conditions should Yii application processing be involved or not)

Thanks ahead for your feedback!

Untested but worth a try:




$app = Yii:createConsoleApplication($config);

$app->setParams(array('name' => 'value'));

$app->run();


class ConsoleProcessCommand extends CConsoleCommand

{

	public function run($args)

	{

    	$args[] = Yii::app()->params['name'];

    	print_r($args);

	}

}



Already tested and working well - thank you very much for your advice!

Rgs,

Ziggi