1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

hw can i execute c++ file using php ??.............

Discussion in 'PHP' started by hansu, Apr 7, 2008.

  1. #1
    am using wamp server in windows.......i used exec and system funtion ...... i user syntax like
    <?php
    exec('g++ filename.cpp' , $result);
    echo $result;
    ?>
    but don't get any result..........wat is problem there ?....... space between g++ and filename is a problem??.......... and wat other solution willbe possible for excute cpp file ??..........
    SEMrush
     
    hansu, Apr 7, 2008 IP
    SEMrush
  2. fireworking

    fireworking Peon

    Messages:
    460
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You cant. C++ is client based. PHP is server based. You need to compile C++.
     
    fireworking, Oct 4, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Are you use you have authorization to use exec. Chances are you are not, otherwise the output will be made.

    When you echo the output, what does it say?

    Peace,
     
    Barti1987, Oct 4, 2008 IP
  4. Panzer

    Panzer Active Member

    Messages:
    381
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Exec can work to say execute a shell script on your server. You could write that shell script to do whatever you need; compile some code.
     
    Panzer, Oct 4, 2008 IP
  5. ZenOswyn

    ZenOswyn Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    For the code you're using, you'd need to modify it a bit to work.

    
    <?php
    exec('g++ filename.cpp -o programname.out' , $result);
    echo $result;
    exec('./programname.out' , $result);
    echo $result;
    ?>
    
    Code (markup):
    But that's assuming that you have got the permissions to run g++ on your hosting account, and from PHP... Honestly, I hope it doesn't work, because that host would have horrid security in place.

    You could also just write the web application in C++ if you wanted to be more direct.
     
    ZenOswyn, Oct 4, 2008 IP