0

I am running XAMPP on windows 10 and in my PHP code, I have the following lines of code.

exec('C:\cygwin64\bin\gcc', $res, $ret);
var_dump($res);
var_dump($ret);

However, I am getting the following output:

array(0) {
}
int(1)

I've tried replacing 'C:\cygwin64\bin\gcc' with 'C:\cygwin64\bin\gcc.exe' and 'gcc' but none of them seem to work. I also tried replacing the backslashes with forward slashes. When I type 'gcc' into cmd, I see the expected output as shown below. When I tried to compile C programs (using absolute paths) with gcc through PHP, no output is produced (no compilation takes place).

gcc: fatal error: no input files
compilation terminated.

Other system calls, like "dir", work fine and the same problem persists when using system() instead of exec(). I also understand that this question was addressed on stackoverflow in Compile C++ file Using PHP but the accepted solution does not work in my case.

Why does this happen and how can I collect further information for debugging?

Community
  • 1
  • 1

1 Answers1

2

gcc echoes to stderr, so you should redirect output to stdout, like this:

exec('C:\cygwin64\bin\gcc 2>&1', $res, $ret);
apoq
  • 1,454
  • 13
  • 14