I'm working on a custom Cron and I want find the best way to call other commands from the Cronjob code in magento2 (programmatically).
For example: When running cli "php bin/magento cache:clean" and so on or my custom console commands.
I try this code but, it is not work..
namespace AmirHome\Cron;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Application;
...
$arguments = new ArrayInput(['command' => 'my:custom:command']);
$this->getApplication()->find('my:custom:command')->run($arguments,
$output);
$arguments = new ArrayInput(['command' => 'cache:flush']);
$this->getApplication()->find('cache:flush')->run($arguments, $output);
Error: Call to undefined method AmirHome\Cron\MyCode::getApplication()