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).
-
<?
-
if( strtolower(substr($argv[1],-4))!='.exe' ) $argv[1].='.exe';
-
$p=proc_open($argv[1]
-
,array(array('pipe','r'),array('pipe','w'),array('file','error.txt','a'))
-
,$pipes);
-
/* ,null
-
,null
-
,array(array('bypass_shell',true)));*/
-
if( is_resource($p) )
-
{
-
print_r(proc_get_status($p));
-
sleep(1);
-
$str=shell_exec('tlist|findstr /i "'.$argv[1].'"');
-
echo "$str\n";
-
sscanf($str,'%d',$pid);
-
echo "PID: $pid\n";
-
$r=proc_close($p);
-
echo "<$r>\n";
-
}
-
?>
-