public setCommand ( string $command ) : static | ||
$command | string | the command or full command string to execute, like 'gzip' or 'gzip -d'. You can still call addArg() to add more arguments to the command. If $escapeCommand was set to true, the command gets escaped through escapeshellcmd(). |
return | static | for method chaining |
public function testCanAddArguments() { $command = new Command(array('locale' => 'en_US.UTF-8')); $command->setCommand('test'); $command->setArgs('--arg1=x'); $command->addArg('--a'); $command->addArg('--a', '中文字äüp'); $command->addArg('--a', array("v'1", 'v2', 'v3')); $command->addArg('-b=', 'v', false); $command->addArg('-b=', array('v4', 'v5', 'v6')); $command->addArg('-c', ''); $command->addArg('some name', null, true); $this->assertEquals("--arg1=x --a --a '中文字äüp' --a 'v'\\''1' 'v2' 'v3' -b=v -b='v4' 'v5' 'v6' -c '' 'some name'", $command->getArgs()); $this->assertEquals("test --arg1=x --a --a '中文字äüp' --a 'v'\\''1' 'v2' 'v3' -b=v -b='v4' 'v5' 'v6' -c '' 'some name'", $command->getExecCommand()); }
/** * @param $cmd * * @return mixed * @throws Exception */ private function execute($cmd) { $command = new Command(); $command->setCommand($cmd); if ($command->execute()) { return $command->getOutput(); } else { throw new Exception($command->getError()); } }