I'm trying to run a C program through PHP exec() function. All is running well in my localhost machine, but when running it in hosting server, C program with pow() function that have variables as argument just won't execute.
I asked the customer support of that hosting, they said that executing C programming language is not supported on their server.
But what is strange for me is, why is my another C program is running well on that server, it just that one code that has pow() with variable as parameter in it that won't run.
Here is my code:
PHP
public function index() {
//runs well
$varExec = exec(app_path() . "/Exec/checkfuncpow.exe");
var_dump($varExec);
echo "<br/>";
//this the one that is not running
$varExec = exec(app_path() . "/Exec/checkfuncpowwithvar.exe");
var_dump($varExec);
}
Results:
string(8) "9.000000"
string(0) ""
checkfuncpow.c
#include <stdio.h>
#include <math.h>
int main() {
printf("%f", pow((double)3, (double)2));
return 0;
}
checkfuncpowwithvar.c
#include <stdio.h>
#include <math.h>
int main() {
double param = 3;
printf("%f", pow(param, (double)2));
return 0;
}
Both code was compiled with the mandatory -lm flag to link to math library
gcc checkfuncpow.c -o ./Exec/checkfuncpow.exe -lm
gcc checkfuncpowwithvar.c -o ./Exec/checkfuncpowwithvar.exe -lm
So the ultimate question is is that really because the server does not support it? Or it should be able to run but the customer support didn't have a clue about the problem , so they just saying what is easy for them?