检查exec()是否成功运行 [英] Checking exec() runs successfully or not

查看:109
本文介绍了检查exec()是否成功运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让我们知道php中的exec()命令是否成功执行,因此我可以相应地回显某些消息. 我尝试了以下代码,但问题是exec()是否成功运行,是否总是echo "PDF not created"并且从不回显成功创建的pdf.请让我知道如何执行exec()的执行检查,以便我可以相应地回显消息 谢谢,

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";
?>

推荐答案

根据PHP的 exec quickref ,您可以传递指针以获取命令的输出和状态.

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";
}
?>

如果要枚举可能的错误,可以在 hiteksoftware

If you want to enumerate the possible errors, you can find the codes over at hiteksoftware

这篇关于检查exec()是否成功运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆