PHP/web programming noob/running executables

Discussion in 'PHP' started by Quo_Vadis, Oct 17, 2012.

  1. #1
    Hi all. First post in these forums. I am an experienced C/C++/Java/C# programmer but have never done any web development. I have a pretty basic question about running executables on a server via php. I gather this is not a good idea, basically. I have some (large-ish) programs written in C that I would like to execute and get the results into a browser. Is there a 'safe' way of doing this? I would really rather not reimplement my programs in php if I can possibly avoid that.
     
    Quo_Vadis, Oct 17, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Using exec or system should work for this. You need to build an effective interface to handle and return the data you need in php. If you're looking at returning huge amounts of data, this might not be the most effective way to accomplish it.
     
    jestep, Oct 17, 2012 IP
  3. Quo_Vadis

    Quo_Vadis Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you. I figured the issue is possibly where you permit the user to enter an executable name which would be a bad idea.
     
    Quo_Vadis, Oct 17, 2012 IP
  4. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #4
    I'm a bit rusty on this, but I think you can just use the backtick operator:

    $output = `dig www.google.com`; // The backticks contain exactly what you'd normally enter at the commandline
    var_dump($output);
    PHP:
    $output should be an array of strings with the output from the program.
     
    Wogan, Oct 17, 2012 IP