By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,773 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,773 IT Pros & Developers. It's quick & easy.

proc_open with pipes

P: 62
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.  
Jun 16 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.