I want to compile a C/C++ file from php script and generate an error file in Windows 7. I am using MinGW32 as C compiler whose path is included in Environment variables (PATH='C:\MinGW32\bin') and WAMP 2.2. Tried using the below php scripts, error file is generated but it is empty ($ferr.err is 0kb).

     // Type 1
     echo `gcc -o $fexe $fsource 2> $ferr.err`;

     // Type 2
     $command = "gcc -o $fexe $fsource 2> $ferr.err";
     $result = shell_exec($command);

     // Type 3
     system("gcc -o $fexe $fsource 2> $ferr.err");   

What is the reason? How to solve this problem?

Thanks in advance..

Is it just related to gcc? What if you execute dir > dirlist.txt

Yes it is related to gcc.
dir > dirlist.txt works fine.

Check it's permissions, appears to be able to create a file, but not write to it.


This is the screenshot of compiling my php file (e.g. hell.php). The php file contains the following code,

echo `gcc hell.c`;

and my C file (hell.c) contains the below code.

int main()
    printf("Hello World
    return 0;

Now I want the error message to be passed into an error file such as hell.err.
I don't think there is any permission issue. I hope my query is clear to you now.

I mentioned it, because I thought you were on a *nix machine. Have you tried with filenames without the dollar sign?