在PHP脚本中运行Symfony2命令(推进:构建)

在PHP脚本中运行Symfony2命令(推进:构建),php,symfony,propel,Php,Symfony,Propel,我想在PHP脚本中运行一个控制台命令。通常是通过CLI完成的,因此我尝试对其进行编辑,结果如下: use Symfony\Component\Debug\Debug; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Comp

我想在PHP脚本中运行一个控制台命令。通常是通过CLI完成的,因此我尝试对其进行编辑,结果如下:

use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Propel\PropelBundle\Command\BuildCommand;

set_time_limit(0);

require_once '/home/core/site/app/bootstrap.php.cache';
require_once '/home/core/site/app/AppKernel.php';
Debug::enable();

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();

$application = new Application($kernel);//->find('propel:build');
$application->setAutoExit(false);
$application->add(new BuildCommand());

$input = new ArrayInput(array('command' => 'propel:build', '--insert-sql' => true));
$output = new BufferedOutput();
$application->run($input, $output);

echo '<pre>';
var_dump($output->fetch());
但是我的输出是[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException],您请求了一个不存在的服务配置


我怎样才能解决这个问题呢?

我不是100%确定,但我认为问题在于您提前访问服务容器。尝试在$application->run$input,$output;之后访问它;。容器应该可以通过$kernel->getContainer访问