如何通过php system()函数显示或捕获gcc编译器的错误字符串 [英] how to display or catch the error string of gcc compiler through php system() function

查看:49
本文介绍了如何通过php system()函数显示或捕获gcc编译器的错误字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用php system()函数从命令行调用gcc编译器来编译c程序。我的c程序名是code.c,如果我正在编译像这个系统这样的正确程序('gcc code.c');它成功生成了可执行文件a.exe。我可以简单地使用这个系统显示输出('a');



但是如果我编译错误的ac程序那么system()函数没有显示任何错误,即使我指定这样的返回参数



system('gcc code.c',$ error);

echo $ error;



它不会显示任何错误。它只显示1作为程序的返回值我猜。



如果我编译错误的c程序,我想显示gcc编译器生成的错误。我正在开发窗口平台。



如果我能做到这个PHP的其他功能那么请帮忙谢谢。

I'm using php system() function to call gcc compiler from command line for compiling the c program. my c program name is code.c if I'm compiling a correct program like this system('gcc code.c'); it successfully generating the executable file a.exe. i can display the output simply using this line system('a');

but if I compile a c program with errors then system() function is not displaying any error, even if I specify return argument like this

system('gcc code.c',$error);
echo $error;

it does not display any error. it just display 1 as the return value of the program i guess.

i want display the error generated by gcc complier if I compile c program with errors. And I'm working on window platform.

if i can do this some other function of php then please help thanks.

推荐答案

错误);

echo
error);
echo


错误;



它确实不显示任何错误。它只显示1作为程序的返回值我猜。



如果我编译错误的c程序,我想显示gcc编译器生成的错误。而且我正在开发窗口平台。



如果我可以执行这个PHP的其他功能那么请帮助谢谢。
error;

it does not display any error. it just display 1 as the return value of the program i guess.

i want display the error generated by gcc complier if I compile c program with errors. And I'm working on window platform.

if i can do this some other function of php then please help thanks.


system 只是 PHP为执行提供的几个函数之一命令 [ ^ ]。 />
可能 exec (或可能 proc_open )更符合您的需求。
system is just one of the several functions PHP provides for executing commands[^].
Probably exec (or possibly proc_open ) fits better your needs.


这篇关于如何通过php system()函数显示或捕获gcc编译器的错误字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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