Compiling C++ files using PHP

Discussion in 'PHP' started by Mohamed Monem, Mar 2, 2009.

  1. #1
    Hello,

    I'm a beginer in using PHP just learned it 2 day ago :) , I want to compile c++ files and get the output in file
    what r all the requerments I need to this , and how can I do this

    Thanx in advance.

    -------------
    Mohamed
     
    Mohamed Monem, Mar 2, 2009 IP
  2. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $descriptorspec = array(
         0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
         1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
         2 => array("file", "filename.txt", "w") // stderr is a file to write to
      );
    $command = "g++ cplusplusfile.cpp";
    proc_open($command,$descriptospec,$output);
    
    PHP:
    Set $command to whatever command you want to execute to compile the C++ program.
     
    Shoro, Mar 2, 2009 IP
  3. Mohamed Monem

    Mohamed Monem Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanx Shoro

    it works and the output file created but the file contain

    "'g++' is not recognized as an internal or external command,
    operable program or batch file."

    instead of the output ?
     
    Mohamed Monem, Mar 3, 2009 IP
  4. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #4
    I think its gc++ and not g++
     
    harrisunderwork, Mar 3, 2009 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I think you're wrong, at least if you're talking about the GNU compiler commonly found on Linux.
     
    SmallPotatoes, Mar 3, 2009 IP
  6. w0tan

    w0tan Peon

    Messages:
    77
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I wouldn't expect this to work if you're on any kind of shared hosting. Access to compilers is almost always restricted due to security problems. There are a few hosts that allow them (nearlyfreespeech being one of them).

    Why are you trying to do this exactly?
     
    w0tan, Mar 3, 2009 IP
  7. canishk

    canishk Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It will work in our localhost machines, but not sure with site hosting servers.
     
    canishk, Mar 3, 2009 IP
  8. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #8
    Your web host will never allow you to compile arbitary c++ program and run it on there server.
     
    it career, Mar 3, 2009 IP
  9. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #9
    bomoh% ssh yoohoo.dreamhost.com
    Linux yoohoo 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+++opt+c6+gr2b-v6.192 #1 SMP Wed Dec 14 17:06:16 PST 2005 i686 GNU/Linux
                                '||                      
       .... ...   ...     ...    || ..     ...     ...   
        '|.  |  .|  '|. .|  '|.  ||' ||  .|  '|. .|  '|. 
         '|.|   ||   || ||   ||  ||  ||  ||   || ||   || 
          '|     '|..|'  '|..|' .||. ||.  '|..|'  '|..|' 
       .. |                                              
        ''                                               
     Welcome to yoohoo.dreamhost.com
    
    Any malicious and/or unauthorized activity is strictly forbidden.
    All activity may be logged by DreamHost Web Hosting.
    
    yoohoo% cat > test.c
    #include <stdio.h>
    #include <string.h>
    int main() { printf("hello world\n"); }
    yoohoo% g++ test.c
    yoohoo% ./a.out
    hello world
    Code (markup):
     
    SmallPotatoes, Mar 3, 2009 IP
  10. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Obviously either g++ isn't installed on the server, or you aren't allowed to use it.
     
    Shoro, Mar 5, 2009 IP
  11. Mohamed Monem

    Mohamed Monem Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11

    g++ installed , and I'm on the localhost on my PC ?
     
    Mohamed Monem, Mar 7, 2009 IP
  12. cveks

    cveks Member

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #12
    didnt know that this is possible
     
    cveks, Mar 7, 2009 IP
  13. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #13
    look in your bin folder to get the correct name that its under
     
    atlantaazfinest, Mar 7, 2009 IP