0
votes

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
Can you call gcc with full absolute path? - Yunnosch
Aside: gcc -o code.c code seems strange, shouldn't it be gcc -o code.exe code.c or gcc -o code code.c ? - Yunnosch
I smell a deeeep security hole being dug. - Eugene Sh.
@EugeneSh. Sounds interesting, please elaborate. Do you think of a php script which compiles uploaded free text to executables and then maybe even executes them? - Yunnosch
Just hope you don't use this to let people upload code to your server. You'll get hacked in seconds. - Bo Persson

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.