PHP exec()在输出中未返回错误消息 [英] PHP exec() not returning error message in output

查看:152
本文介绍了PHP exec()在输出中未返回错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以XML格式获取svn命令的某些输出.当我输入有效参数时,输出正常.但是,当我输入错误的密码时,输出不会显示错误消息. 这是PHP代码:

I am trying to get certain output for svn command in XML format. Output is ok when I type valid parameters. However, when I type in wrong password, output does not show error message. This is the PHP code:

exec('/usr/bin/svn --username something --password something --non-interactive log -r HEAD --xml --verbose http://a51.unfuddle.com/svn/a51_activecollab/', $output);

这是我进入终端的输出:

Here is output I get in the terminal:

<?xml version="1.0"?>
<log>
svn: OPTIONS of 'http://a51.unfuddle.com/svn/a51_activecollab': authorization failed: Could not authenticate to server: rejected Basic challenge (http://a51.unfuddle.com)

这是我使用var_dump从$ output变量获得的输出:

And here is the output I get from the $output variable with var_dump:

array(2) {
[0]=>
string(21) "<?xml version="1.0"?>"
[1]=>
string(5) "<log>"
}

如您所见,$ output变量不返回输出的第三行,而终端则返回.请帮助我获得与终端输入相同的输出(我什至尝试过使用shell_exec()或system()方法,但它们返回的输出与exec()相同)如何获得完整的输出? 预先谢谢你!

As you can see the $output variable does not return third line of output, where terminal does. Please help me to get the same output as I get in terminal (I even tried with shell_exec() or system() methods but they return the same output as exec()) How do I get full output? Thank you in advance!

推荐答案

您还需要捕获stderr.

stderr重定向到stdout应该可以解决问题.将2>&1附加到命令末尾.

Redirecting stderr to stdout should do the trick. Append 2>&1 to the end of your command.

例如

exec("/usr/bin/svn --username something --password something --non-interactive log -r HEAD --xml --verbose http://a51.unfuddle.com/svn/a51_activecollab/ 2>&1", $output);

这篇关于PHP exec()在输出中未返回错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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