Checking exec() runs successfully or not

Viewed 70658

I have been trying to let know know if the exec() command in php executes successfully or not so i can echo certain messages accordingly. I tried the following piece of code but the problem with it is that whether exec() runs successfully or not it always echo "PDF not created" and never echo pdf created successfully. Kindly let me know how can i perform the check on the execution of exec() so i can echo messages accordingly Thanks,

<?php
if (exec('C://abc//wkhtmltopdf home.html sample.pdf'))
echo "PDF Created Successfully";
else
echo "PDF not created";
?>
5 Answers

i do work for me

for system linux and lang:php,laravel

exec('/usr/bin/tesseract 2.png out1 -l '.$lang,$output,$error);
           return (!$error)? "success":"Error";

I would suggest to use the next method if you don't care about return code:

private function execCommand($command) {
    exec($command, $output, $return);

    return $return === 0;
}

then simply call it like:

if ($this->execCommand("C://abc//wkhtmltopdf home.html sample.pdf")) {
    echo "Success";
} else {
    echo "Error";
}
Related