Results 1 to 2 of 2

Thread: Executing local programs thru PHP...

  1. #1
    Join Date
    Jan 2003
    Location
    DE
    Posts
    27

    Executing local programs thru PHP...

    Here's a new one:

    <?php
    exec("usr/bin/uptime", $result);
    echo $result;
    ?>

    Simple huh!?
    So why is the output instead of the real uptime of the system just Array?
    According to the function description at http://www.php.net/manual/en/function.exec.php the functions should spit out a string and not an array, shouldn't it!?
    And why doesn't it print out the data, it only produces the array whatever output... argh!

  2. #2
    Join Date
    Mar 2003
    Location
    Jacksonville, Florida
    Posts
    52
    What you want is

    <?php
    $result = exec("usr/bin/uptime");
    echo $result;
    ?>

    The last line is returned as a string. In this case that is all you care about, especially because it has 1 line.
    If called like this

    <?php
    exec("usr/bin/uptime", $result);
    echo $result[0];
    ?>

    it puts ALL the lines of the result (what ever is printed to stdout) in the array, in order to directly access every line that is output, not just the last.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •