1.11M Members

Compiling a c program from php script

 
0
 

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.

 
0
 

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 …

 
0
 

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

 
0
 

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.

 
0
 

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;
}

 
0
 

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.

 
0
 

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...??

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: