includes/functions.php
changeset 1310 41ac3758ba79
parent 1301 bd9e124f5904
child 1322 8496dd47b87c
equal deleted inserted replaced
1309:2a14b5a25338 1310:41ac3758ba79
  5272 	}
  5272 	}
  5273 	return false;
  5273 	return false;
  5274 }
  5274 }
  5275 
  5275 
  5276 /**
  5276 /**
  5277  * Implementation of the "which" command in native PHP.
  5277  * Return the OS's PATH variable.
  5278  * @param string command
  5278  * @return string
  5279  * @return string path to executable, or false on failure
  5279  */
  5280  */
  5280 
  5281 
  5281 function get_system_path()
  5282 function which($executable)
       
  5283 {
  5282 {
  5284 	$path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false );
  5283 	$path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false );
  5285 	if ( !$path )
  5284 	if ( !$path )
  5286 		// couldn't get OS's PATH
  5285 		// couldn't get OS's PATH
  5287 		return false;
  5286 		return false;
  5288 		
  5287 		
       
  5288 	return $path;
       
  5289 }
       
  5290 
       
  5291 /**
       
  5292  * Implementation of the "which" command in native PHP.
       
  5293  * @param string command
       
  5294  * @return string path to executable, or false on failure
       
  5295  */
       
  5296 
       
  5297 function which($executable)
       
  5298 {
       
  5299 	$path = get_system_path();
       
  5300 	if ( empty($paths) )
       
  5301 		return false;
       
  5302 	
  5289 	$win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' );
  5303 	$win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' );
  5290 	$extensions = $win32 ? array('.exe', '.com', '.bat') : array('');
  5304 	$extensions = $win32 ? array('.exe', '.com', '.bat') : array('');
  5291 	$separator = $win32 ? ';' : ':';
  5305 	$separator = $win32 ? ';' : ':';
  5292 	$paths = explode($separator, $path);
  5306 	$paths = explode($separator, $path);
       
  5307 	
  5293 	foreach ( $paths as $dir )
  5308 	foreach ( $paths as $dir )
  5294 	{
  5309 	{
  5295 		foreach ( $extensions as $ext )
  5310 		foreach ( $extensions as $ext )
  5296 		{
  5311 		{
  5297 			$fullpath = "$dir/{$executable}{$ext}";
  5312 			$fullpath = "$dir/{$executable}{$ext}";