我正在使用Symfony 2控制台组件编写一个控制台应用程序,并且我想在我的应用程序的第一行之前(或作为)运行一个控制台清除命令。
我做了一些研究,正在努力寻找这是否可能。
发布于 2016-04-04 14:07:42
我一直在寻找类似的功能。据我所知,symfony控制台中没有内置的东西可以清除屏幕,但是您仍然可以通过使用转义代码重置终端来实现clear行为,如下所示:
$output->write(sprintf("\033\143"));请参阅文章"Clear the Ubuntu bash screen for real“和"What commands can I use to reset and clear my terminal?”以获得更详细的代码解释,以及这个symfony控制台pull request,我从那里获得了代码,它试图模拟clear功能。
发布于 2015-08-27 15:08:00
正如doc所说,您可以使用如下内容:
$kernel = $this->getContainer()->get('kernel');
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput(array(
'command' => 'cache:clear',
));
// You can use NullOutput() if you don't need the output
$output = new BufferedOutput();
$application->run($input, $output);
// return the output, don't use if you used NullOutput()
$content = $output->fetch();当您使用命令时,您的命令必须扩展ContainerAwareCommand,以便可以访问容器和您的服务。
https://stackoverflow.com/questions/32240463
复制相似问题