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";
?>
According to PHP's exec quickref, you can pass pointers in to get the output and status of the command.
<?php
exec('C://abc//wkhtmltopdf home.html sample.pdf', $output, $return);
// Return will return non-zero upon an error
if (!$return) {
echo "PDF Created Successfully";
} else {
echo "PDF not created";
}
?>
If you want to enumerate the possible errors, you can find the codes over at hiteksoftware