tags:

views:

60

answers:

2

I just spent a few hours pulling my hair out over this. I'm trying to get gcc to compile a file from within PHP.

    $command = "/usr/bin/gcc /var/www/progpad/temp/tNu7rq.c -o /var/www/progpad/temp/tNu7rq.out";
    exec($command, $output, $returnVal);
    echo $returnVal."<br />"; //returns 1 and no output file created.

I'm running this on my own ubuntu server and both

/var/www/progpad/
/var/www/progpad/temp/

have chmod 777 set. If I copy and paste the command string, and paste it into the terminal it works perfectly.

Also if I replace the command string with something like

$command = "echo test > test.txt";

Then this has no problem creating the text file. What could I possibly be doing wrong here???

A: 

You are compiling the program, but you are never executing it.

  1. Check to see that the compiled program works by running foo.out.
  2. Assuming foo.out compiled correctly, then run foo.out.
I forgot to mention that the output file is not appearing at all. Ill edit my question.
teehoo
A: 

I found the problem. I was randomly generating file names, and creating the file. I was trying to compile the file before running fclose() on the file handler.

teehoo