Skip to content

Commit

Permalink
Add timeout option to the shell:exec command.
Browse files Browse the repository at this point in the history
  • Loading branch information
boite committed Sep 23, 2016
1 parent 8b026b4 commit eaac7c5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Command/ShellExecCommand.php
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -22,12 +23,19 @@ public function configure()
{
$this
->setName('shell:exec')
->setDescription('Initiate a reboot.')
->setDescription('Execute the given command line in Bash.')
->addArgument(
'command-line',
InputArgument::REQUIRED,
'The command and arguments to be executed by the shell.'
)
->addOption(
'timeout',
't',
InputOption::VALUE_REQUIRED,
'The maximum permitted execution time in seconds.',
60
)
;
}

Expand All @@ -38,7 +46,8 @@ public function execute(InputInterface $input, OutputInterface $output)
'bash',
'-c',
$input->getArgument('command-line')
)
),
$input->getOption('timeout')
);

if ($p->run()) {
Expand All @@ -58,11 +67,12 @@ public function execute(InputInterface $input, OutputInterface $output)
/**
* @return \Symfony\Component\Process\Process
*/
private function getProcess($arguments)
private function getProcess($arguments, $timeout)
{
return $this
->processBuilder
->setArguments($arguments)
->setTimeout($timeout)
->getProcess()
;
}
Expand Down

0 comments on commit eaac7c5

Please sign in to comment.