使用 PHP 的 exec() 函数(或类似函数),如何显示终端错误输出?
可能的重复:
我怎样才能知道命令中的错误在 exec 函数中?
我只是想知道是否有一种方法(使用 PHP)将编译错误信息从终端输出到浏览器?
例如: 如果您使用此代码在终端中执行...
gcc -o try try.c
...并假设“try.c”有一些错误。 终端将输出如下内容:
- try.c In function 'main':
- try.c:27 'x' undeclared (first use in this function)
- try.c:27 (每个未声明的标识符仅报告一次
- try.c: 27 对于它出现的每个函数。)
同时,使用这个 PHP 代码...
浏览器不会像终端那样返回任何输出。是否有可能直接或间接地将终端显示的错误详细信息传递到浏览器上显示?
非常感谢。
Possible Duplicate:
How can I know the error in command in an exec function?
I am just wondering if there's a way (using PHP) to output the compile error information from the terminal to the browser?
For example:
If you use this code to execute in the terminal...
gcc -o try try.c
...and assuming the "try.c" have some errors.
The terminal will output something like this:
- try.c In function 'main':
- try.c:27 'x' undeclared (first use in this function)
- try.c:27 (Each undeclared identifier is reported only once
- try.c:27 for each function it appears in.)
Meanwhile, using this PHP code...
<?php
exec("gcc -o try try.c");
?>
The browser does not return any output like the terminal does. Is there a possible way direct or indirect that the error details that the terminal showed can be passed to the be displayed on a browser?
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 @hakre 在评论中指出的那样 - 您可以简单地重定向 STDERR 流,但这里有另一个解决方案:
如果执行成功 - 每个程序都应返回 0 的退出状态,任何其他代码都应意味着某种错误。
As @hakre has noted in the comments - you can simply redirect the STDERR stream, but here's another solution:
If execution was successful - each program should return an exit status of 0 and any other code should mean some kind of an error.