Connecting Tech Pros Worldwide Help | Site Map

proc_open with pipes

  #1  
Old June 16th, 2009, 07:43 AM
Newbie
 
Join Date: Dec 2006
Posts: 13
I don't know why the following script intermittently crashes when I remove the sleep() call. I believe the pipes were not properly set yet before the shell statement was called, which used pipes also. This is on Windows 98 (I know it's a bit old), with PHP 5.2.5, and tlist and findstr came from the resource toolkit (ftp://ftp.microsoft.com/services/tec...s/win98/reskit).

BTW I am trying to get the real PID of the process which was patched in version 5.3, but I would still want to know why the script completely fails (becomes unresponsive and cannot be killed).

Expand|Select|Wrap|Line Numbers
  1. <?
  2. if( strtolower(substr($argv[1],-4))!='.exe' ) $argv[1].='.exe';
  3. $p=proc_open($argv[1]
  4.     ,array(array('pipe','r'),array('pipe','w'),array('file','error.txt','a'))
  5.     ,$pipes);
  6. /*    ,null
  7.     ,null
  8.     ,array(array('bypass_shell',true)));*/
  9. if( is_resource($p) )
  10. {
  11.     print_r(proc_get_status($p));
  12.     sleep(1);
  13.     $str=shell_exec('tlist|findstr /i "'.$argv[1].'"');
  14.     echo "$str\n";
  15.     sscanf($str,'%d',$pid);
  16.     echo "PID: $pid\n";
  17.     $r=proc_close($p);
  18.     echo "<$r>\n";
  19. }
  20. ?>
  21.  
Reply

Tags
pid, pipe, proc_open, shell_exec


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent help please -- ffmepg proc_open return 127, no execution, xhe answers 6 June 2nd, 2008 11:37 AM
help with proc_open(): some apps work - some don't arielCo answers 1 November 25th, 2005 01:15 AM
proc_open, write error to var instead file?? Muffinman answers 0 July 17th, 2005 11:31 AM
proc_open and blocking fread / tri-directional pipes Christian Hammers answers 0 July 17th, 2005 05:53 AM