Skip to content
September 26, 2007 / ranacse05

Compile C program using PHP-5


To day i successfully compile a .c program using PHP-5. It just simple.I just use “System()” function on PHP-5. :)

17 Comments

Leave a Comment
  1. Sona / Mar 22 2008 8:58 am

    how did u compiled…. plz tell me how??
    i used system(“cc sam.c”); but itz not working …

  2. ranacse05 / Mar 26 2008 5:27 am

    i compile it using system(“gcc main.c”); remember u have to make the directory permission ’0777′ .

  3. php programmer / May 15 2008 12:33 pm

    shell_exec() function can also be called with command line arguments.
    should give the same result as system()?

  4. ranacse05 / May 16 2008 9:09 am

    @php programmer
    ya u r right :)

  5. ashish / May 26 2008 11:39 am

    i want to run a c program via php. the program also has scanf commands. how do i give these inputs. i canntouse command line arguments as the inputs are to be given from dynamically collected data over the time.

    • ranacse05 / Oct 25 2009 8:10 pm

      how about u read the inputs form a file ?

      i think that can help u .

  6. Rahid Hasan Robin / Oct 22 2009 8:30 am

    I want to see all compiling error in php. How could it possible pls help me.

    Thanks for this helpful post

    • ranacse05 / Oct 25 2009 8:08 pm

      u need to call an shell script for that in that shell script put the compile command and save the output of those command on another file then read the file and do what ever u want .

      there maybe some easy way too.

  7. Miljan / Apr 24 2010 3:11 pm

    i am making online compiler for college… i need to now when i assign text filed values to variable what i should put in system(gcc and then?) ? pls help its urgent

    • ranacse05 / May 17 2010 7:50 pm

      u have to filter the text before u pass that to the system, bcoz u need make sure that there is not harmful command , or u can lost ur server data :D

  8. sharmilli / Feb 23 2011 10:04 am

    I tried shell_exec(‘gcc -0 Compile Compile’); , system(‘gcc -0 Compile Compile’);, exec(‘gcc -0 Compile Compile’); to run my C code but its not working.

    • ranacse05 / Feb 23 2011 5:48 pm

      You need to allow those functions on php.ini files , usually those are not allowed in shared hosting .

      • sharmilli / Feb 24 2011 4:22 am

        I could use the command for running ‘./compile’ but.

  9. Tinesh / Aug 8 2011 7:31 pm

    i’m trying to design an online compiler.. , i’m not able to run this command system(‘gcc hello.c) from my php file… ,but system(‘./a.out’) works

  10. rock / Nov 24 2011 12:48 am

    wud u plz send me the code i m in trble…
    my emailid:rock389@yahoo.com

    • ranacse05 / Nov 24 2011 12:57 am

      Hey Rock please check the phpinfo() for the exec, system etc functions most of the hosting dont allow to call those functions , you can try in your VPS or local server .

  11. Subbaiyan / May 8 2012 2:13 pm

    c & C++ Program code input textarea in PHP and out put in div any one do this work replay to me and send the php code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.