I'm trying to compile *.c file using shell_exec(gcc -o code.c code); when I die dump I get that gcc is not recognized as a command but I do have it installed on my command. I can do shell_exec('ls') I also have the gcc path set I cain't think of anything else. can you? thanks ahead !
1 Answers
0
votes
Please bear in mind at the moment I'm getting errors but gcc is actually compiling from a php function call in the web browser.
2>&1 means redirect stderr to stdout this link helped hope it can help you http://wiki.bash-hackers.org/howto/redirection_tutorial.
function compile()
{
$output = shell_exec("C:\MinGW\bin\gcc.exe -o $code 2>&1");
dd($output);
}
gcc.exe: fatal error: no input files\n
compilation terminated.\n
I can now use gcc with php shell_exec() function the errors I'm getting are now a simple understanding of the absolute paths my files have and making the correct gcc command to compile, the next step once I have actually managed to compile the code.c in .a.out will be to execute the .a.out file. I will share updates here once it is accomplished. Thanks for your help.
gcc -o code.c codeseems strange, shouldn't it begcc -o code.exe code.corgcc -o code code.c? - Yunnosch