getting process id in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shoonya
    New Member
    • May 2007
    • 160

    getting process id in php

    i am using windows XP

    and using
    popen("start notepad","r");

    to start a note pad
    now how can i get the process id of this notepad

    shoonya
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Check out the proc_get_status () function.
    It should get you what you need.

    Comment

    • shoonya
      New Member
      • May 2007
      • 160

      #3
      thanks a lot atil

      but when I am using popen to open the note pad it's giving error
      [PHP]
      PHP Warning: proc_get_status (): supplied resource is not a valid process resource in C:\Program Files\Apache Group\Apache2\h tdocs\quedge3\i ndex\test.php on line 46[/PHP]

      i think it's looking for a process that has been opened by proc_open but i am not able to get the syntax of proc_open

      so help me out
      i am stuck here for last 2 days :(

      shoonya

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        I managed to get this working using the 'ipconfig' command, didn't manage to get a notepad window. Don't really undestand why you'd want that anyways.

        But anyhow.. this is my code:
        [code=php]
        <?php
        error_reporting (E_ALL);

        $descriptorspec = array(
        0 => array("pipe", "r"),
        1 => array("pipe", "w"),
        2 => array("pipe", "r")
        );

        $process = proc_open('ipco nfig', $descriptorspec , $pipes);

        if (is_resource($p rocess)) {

        // Get the proccess info
        echo "Proccess information:<pr e>";
        $var = proc_get_status ($process);
        print_r($var);
        echo "</pre>";

        // Print stream from proccess
        echo "Process output:<pre>";
        echo stream_get_cont ents($pipes[1]);
        echo "</pre>";
        fclose($pipes[1]);

        // It is important that you close any pipes before calling
        // proc_close in order to avoid a deadlock
        $return_value = proc_close($pro cess);

        // Print return value (0 if success)
        echo "Process returned:<pre>" ;
        echo $return_value ."\r\n";
        echo "</pre>";
        }
        else
        {
        echo "Process failed to open";
        }
        ?>
        [/code]

        This is based on an example found at php.net/proc_open

        Comment

        • shoonya
          New Member
          • May 2007
          • 160

          #5
          ooops
          you have just pasted the example from php.net

          I was not getting the concept of pipes and streams
          so any good tutorial or link will work for me

          shoonya

          Comment

          Working...