I did some reading on these things but still confused until now.What is the difference between these four? I hope someone can give a simple and direct explanation.
system()
passthru()
exec()
shell_exec()

Lets say I have a a shell script called start.sh at /root/scripts. How do I run it using the four commands above? Please give an example.

Also, is there a way for us to check whether the shell scripts ran successfully or not via ny of these four commands mentioned?

Thanks a million
James

    $stat=system('/bin/sh /root/scripts/start.sh', $ret);
    //will use /bin/sh to execute the script
    echo $ret; //echoes return status of command (on 'Nix, 0 for success)
    echo $stat; // echoes output of 'start.sh', if any
    
    $stat=exec('/bin/sh /root/scripts/start.sh', $outarray, $ret);
    // /bin/sh runs the script
    echo $stat; // echoes last line of start.sh output
    echo $ret; // return status of command
    while ($x<count($outarray)) {
        echo $outarray[$x]."\n";
        $x++;
    } // will echo each line of start.sh's output
    
    $resource=passthru('/bin/sh start.sh', $ret);
    // $ret is return value of command
    // $resource is a raw binary stream, say, an image or audio stream....
    
    $stat=shell_exec('ping -t2 yahoo.com');
    // note: it knows what the shell knows, i.e.
    // it knows where 'ping' is ...
    // $stat will be the complete output

    HTH,

      Just an appreciative note.

      good reply from dalecosp.
      I liked the way he presented all the examples, properly with comments.

      wonderful.
      kbrij.

        5 days later

        I have tried all that is possible but p0f still wont run as will not show in the system monitor.

        **Pls see the thread:Running the p0f tool from
        PHP for more information.

        My main purpose here is instead of running p0f on the prompt I can run it using/through a webpage and then view the test.txt through a web page.
        If this is possible, pls give an example on how to do it.
        Thanks a million.Appreciate your help.

          a month later

          I have tried all methods as mentioned earlier.
          Do I need to check for permissions access to that folder?
          This is because the user is running it through a PHP page under Apache.

          Any other things I need to check before I proceed?

            Write a Reply...