diff --git a/src/Phpml/Exception/LibsvmCommandException.php b/src/Phpml/Exception/LibsvmCommandException.php new file mode 100644 index 0000000..01d8079 --- /dev/null +++ b/src/Phpml/Exception/LibsvmCommandException.php @@ -0,0 +1,15 @@ +buildTrainCommand($trainingSetFileName, $modelFileName); $output = ''; - exec(escapeshellcmd($command), $output); + exec(escapeshellcmd($command), $output, $return); + + if ($return !== 0) { + throw LibsvmCommandException::failedToRun($command); + } $this->model = file_get_contents($modelFileName); @@ -168,6 +173,8 @@ class SupportVectorMachine /** * @return array|string + * + * @throws LibsvmCommandException */ public function predict(array $samples) { @@ -178,7 +185,11 @@ class SupportVectorMachine $command = sprintf('%ssvm-predict%s %s %s %s', $this->binPath, $this->getOSExtension(), $testSetFileName, $modelFileName, $outputFileName); $output = ''; - exec(escapeshellcmd($command), $output); + exec(escapeshellcmd($command), $output, $return); + + if ($return !== 0) { + throw LibsvmCommandException::failedToRun($command); + } $predictions = file_get_contents($outputFileName);