1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

compile c program from php page and save output

Discussion in 'PHP' started by gyanu, Jun 21, 2008.

  1. gyanu

    gyanu New Member

    We have built a code to compile C program from text area built in PHP. We have tried all the commands that could be used to compile the program,
    for example exec(), system() and even the shell_exec() commands.
    The problem is still that we are not getting the output. We are sending you the code, Kindly please suggest some solution.



    <?php

    echo "hi its me lalit kumar mishra";
    $t1=$_GET['t1']; // $t1 is file name of user file.

    $t2=$t1;
    $t2 .= '.o'; // we are creating the filename with .o extension

    $j="cd /home/wipro;"; // where the program exist.

    $s ="$j"." gcc -c $t1"; // t1 is user filename with .c extension
    $ss="$j"." gcc -o $t2 $t1"; // t2 is filename with .o extension
    $sss="$j"." ./$t2"; // getting output of c program
    exec($s);
    exec($ss);
    $var1=exec($sss);

    echo "Output of Program= $var1";

    ?>
     

Share This Page