Running a Symfony console command independently

I was trying to find a way to call a console command from another one, while modifying the container parameters, and ended up with this minimum-viable-bootstrap. It almost works - subsequent runs seem to get redefining-class errors. I ended up using Symfony Process instead.

$kernel = new \AppKernel($env, $debug);
$kernel->boot();

/** @var \Symfony\Bundle\FrameworkBundle\Console\Application $app */
$app = new Application($kernel);

$command = new CacheClearCommand();
$command->setApplication($app);
$command->setContainer($kernel->getContainer());

$command->run(new ArgvInput([$_SERVER["PHP_SELF"], "cache:clear"]), $output);