function compile()
{
$a=shell_exec('gcc -o Compile Compile.c');
echo $a;
$b=shell_exec('./Compile');
echo $b;
}

I tried to call the above compile function from the directory /var/www/. I could get the result by manual execution of gcc command but i could not create an executable file by running the same command from php using shell_exec(), though i could get the result of "shell_exec('./Compile'); ". Kindly let me know the issues.

I have never tried such thing. PHP is compiled in C, to have PHP call the compiler is not the logical way to go. What is the need to use PHP on that, do you want the compilation to occur when something comes from net. And maybe the answer is that … what exactly you are trying to do …

Actually i am trying to invoke the compiler from PHP. Would be useful if some one suggest a working function for the same.

Why? If you want someone to spend time explaining how to do something, then you should provide a better answer as to why you want to do it.

I am developing an online testing system through which we can conduct online programming contests.
For the same i want to invoke the C compiler from the php script using the functions like system(), shell_exec(), exec() etc. But the function is not returning the result when i call the C compiler as in the following code:
function compile()
{
$a=shell_exec('gcc -o Compile Compile.c'); //Code is not returning anything
echo $a;
$b=shell_exec('./Compile'); // Code is working
echo $b;
}

A few ideas:

1) The process created by PHP will be run as the PHP user. Does this user have the required permissions.
2) If you're getting errors, you would need to access stderr. Try "2>&1" at the end to redirect stderr to stdout.
3) Compiling takes time, you might want to do it asynchronously with the PHP process and have PHP monitor it. You can use proc_open() and stream_select() to listen to changes. This also gives you access directly to the stderr output which would be useful.

can someone plzz tell me code for compiling c/c++ program via php on windows 7 platform.
i m using xampp on my local machine.
i hv no idea abt hw to do dat...plzzzz help me..
.its very urgent...
wht fuction i cn use...??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.