0

When I try to compile C file with a correct syntax using shell_exec() function its work fine, but the problem is when I do a mistake in the C syntax. I can't get the error message from the output

php code :

<?php
echo shell_exec("gcc C:\\xamppp\\htdocs\\testor\\filec.c -o C:\\xamppp\\htdocs\\testor\\filec.exe");
?>

filec.c code :

#include <stdio.h>
int main(){
print("hello C!");//i wrote print to get an error message
}

cmd command :

**gcc filec.c -o filec.exe**
filec.c: In function 'main':
filec.c:3:1: warning: implicit declaration of function 'print'; did you mean 'printf'? [-Wimplicit-function-declaration]
    3 | print("hello C!");
      | ^~~~~
      | printf
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\escanor\AppData\Local\Temp\ccgCM4xv.o:filec.c:(.text+0x16): undefined reference to `print'
collect2.exe: error: ld returned 1 exit status

but nothing displayed in the browser.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Escanor
  • 95
  • 3
  • 9
  • Not sure if this is the same, basically capturing STDERR - https://stackoverflow.com/questions/15086572/php-how-to-get-shell-errors-echoed-out-to-screen – Nigel Ren May 13 '20 at 09:34
  • Does this answer your question? [PHP - How to get Shell errors echoed out to screen](https://stackoverflow.com/questions/15086572/php-how-to-get-shell-errors-echoed-out-to-screen) – the busybee May 13 '20 at 12:16

0 Answers0