Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying compile a C Code with PHP

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?

like image 850
richardaum Avatar asked Jan 22 '23 15:01

richardaum


1 Answers

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.

like image 151
Gian Avatar answered Jan 29 '23 08:01

Gian