Professional Web Applications Themes

storing the passthru() output as an array - PHP Development

Hi again, Have another problem here I need to get the output of this syntax $ps = (passthru("ps -ef")); and store it in an array line by line, I specifically want to get the Columns of the PID for this command and store it in a selection box . Any Idea how, thanks in advance. Mike...

  1. #1

    Default storing the passthru() output as an array

    Hi again,

    Have another problem here I need to get the output of this syntax

    $ps = (passthru("ps -ef"));

    and store it in an array line by line, I specifically want to get the
    Columns of the PID for this command and store it in a selection box .

    Any Idea how, thanks in advance.


    Mike
    Michael Guest

  2. #2

    Default RE: [PHP] storing the passthru() output as an array


    I don't know if this is the easiest way but a solution

    Pipe ps -ef to a file read the file into an array and do with it what
    you will.

    EG

    $filename = "/tmp/psefdump.txt";
    exec("ps -ef > $filename");

    $lines = file($filename);

    foreach ( $lines as $var ) {
    // Yadda Yadda
    }

    Hope this helps...

    --
    Chris Kay (CK)
    Eleet Internet Services
    M: 0415 451 372
    P: 02 4620 5076
    F: 02 4620 7008
    E: com.au


    -----Original Message-----
    From: Michael P. Carel [mailto:com]
    Sent: Tuesday, 7 October 2003 11:41 AM
    To: php.net
    Subject: [PHP] storing the passthru() output as an array


    Hi again,

    Have another problem here I need to get the output of this syntax

    $ps = (passthru("ps -ef"));

    and store it in an array line by line, I specifically want to get the
    Columns of the PID for this command and store it in a selection box .

    Any Idea how, thanks in advance.


    Mike

    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php
    Chris Guest

  3. #3

    Default Re: [PHP] storing the passthru() output as an array

    On Tue, 7 Oct 2003 09:41:03 +0800, you wrote:
     

    Turn on output buffering, grab the output of your script, then turn it off.
    (ob_start, ob_get_contents, ob_end_clean)

    But that's a hack; you're better off using shell_exec instead of passthru
    David Guest

  4. #4

    Default Re: [PHP] storing the passthru() output as an array

    Thanks it works.
     
    >
    > You can use output buffering to grab the output and explode to put the
    > lines in an array.
    >
    > http://us4.php.net/manual/en/ref.outcontrol.php
    >
    > ob_start();
    > passthru("ps -ef");
    > $ps = ob_get_contents();
    > ob_end_clean();
    >
    > $lines = explode("\n",$ps);
    >
    > - Brad
    >
    > --
    > PHP General Mailing List (http://www.php.net/)
    > To unsubscribe, visit: http://www.php.net/unsub.php[/ref]
    Michael Guest

Similar Threads

  1. Storing server side information into a javasript array
    By patb96 in forum Macromedia ColdFusion
    Replies: 1
    Last Post: May 26th, 12:48 AM
  2. Problem with storing data in an array
    By Romain in forum PERL Beginners
    Replies: 3
    Last Post: April 7th, 10:08 PM
  3. storing an array in a db
    By Alexander Ross in forum PHP Development
    Replies: 3
    Last Post: August 7th, 08:26 PM
  4. [PHP] preventing output dump of passthru()
    By Chris W. Parker in forum PHP Development
    Replies: 5
    Last Post: August 6th, 08:41 PM
  5. preventing output dump of passthru()
    By Chris W. Parker in forum PHP Development
    Replies: 2
    Last Post: August 6th, 12:11 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139