尝试用PHP编译C代码 [英] Trying compile a C Code with PHP

查看:133
本文介绍了尝试用PHP编译C代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为gcc.exe的文件,我有一个php页面...
我想使用:

  gcc test.c 

并且,如果有一些编译错误,我想显示它php页面...
但是我不能。
会发生什么:如果文件是正确的,它会生成.exe文件,
,但如果它错了,什么也不会发生。



任何人都有想法?



Edit [1]:
一些代码:

 <?php 
exec (gccteste.c,$ results);
print_r($ results)
?>

输出:

 code> * Nothing * 

编辑[2]:
我尝试在文本文件中输入gcc:
这种方式(提示符):



gcc test.c> ; teste.txt



在语法上,屏幕上的所有东西都会转到文本文件。






编辑[3]: quantumSoup:
我尝试了,... ...



array(0){} int(1) p>

没有什么...还有什么吗?

解决方案

gcc很可能生成错误输出在 stderr ,它会出现 exec 不捕获在$ results数组。这个解决方案很可能是平台特定的。如果你在一个类Unix环境中工作,可以做类似于 gcc foo.c 2>& 1 的操作,将stderr重定向到stdout。我不知道如何在Windows上实现,或者如果类似的概念存在。



这可以通过管道传输到文件来实现。


I have a file named gcc.exe and I have a php page... I want to use:

gcc test.c

And, if there's some compilation error, I want to show it on the php page... But I can't. What happens is: If the file is correct, it generates the .exe file, but if it's wrong, nothing happens. What I want here, again, is to show all errors.

Anyone has an idea?

Edit[1]: Some code:

<?php
exec("gcc teste.c",$results);
print_r($results)
?>

Output:

*Nothing*

Edit[2]: I tryed put gcc output on a text file: This way (on prompt):

gcc test.c > teste.txt

Teorically, everythings on the screen go to text file. But this was unsucessfuly!



Edit[3]: quantumSoup: I tryed it, and...

array(0) { } int(1)

Nothing... Anything more?

解决方案

gcc is likely to generate error output on stderr, which it would appear exec doesn't capture in the $results array. Solutions to this are likely to be kinda platform-specific. If you're working in a unix-like environment, it would be possible to do something like gcc foo.c 2>&1 to redirect stderr to stdout. I've no clue how one might achieve that on Windows, or if analogous concepts even exist. Perhaps someone else can elaborate if your question is platform-specific.

This is supported by the fact that piping to a file didn't work either.

这篇关于尝试用PHP编译C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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