I have a simple console app using the Symfony console component.
I have two commands (say, cmdOne
and cmdTwo
) which can be called independently easily.
$ myApp.php cmdOne
$ myApp.php cmdTwo
Both commands have a considerable amount of output, which I can easily mute by issuing the -q
option.
Now, I'd like cmdOne
to call cmdTwo
however I'd like cmdTwo
to be quiet. I'm not trying to do anything crazy, but I'm struggling to get anywhere, despite reading through the docs.
Here's my sample code so far (this snippet would be contained within cmdOne->execute()
):
$command = $this->getApplication()->find('cmdTwo');
$input = new ArrayInput(array(
'command' => 'cmdTwo',
'-q' => true
));
$returnCode = $command->run($input, $output);
This runs fine, as in the code command executes, but there's output on the console (generated by cmdTwo
) which I'd like to not show.
Is specifying the -q
option not possible because it's "reserved" (i.e not created by the dev), or am I missing something obvious?
If a command depends on another one being run before it you can call in the console command itself.
The Symfony framework provides lots of commands through the bin/console script (e.g. the well-known bin/console cache:clear command). These commands are created with the Console component. You can also use it to create your own commands.
Easily open Command Prompt by running Windows Run by holding the Windows button and hitting the R button on your keyboard. You can then type "cmd" and press enter, opening Command Prompt. If you're unsure of what commands to use, you can type "Help" into Command Prompt.
Instead of passing the same $output
instance (the one that outputs to your current console) create an instance of NullOutput
$returnCode = $command->run($input, new \Symfony\Component\Console\Output\NullOutput);
It basically is a blackhole - it accepts output and silently drops it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With