Using popen() to Read the Output of the Unix who Command : popen « File Directory « PHP






Using popen() to Read the Output of the Unix who Command

 
<html>
<head>
<title>Using popen() to Read the Output of the Unix 'who' Command</title>
</head>
<body>
<div>
<h1>Administrators currently logged on to the server</h1>
<?php
$ph = popen( "who", "r" )or die( "Couldn't open connection to 'who' command" );
$host="demo.com";
while ( ! feof( $ph ) ) {
  $line = fgets( $ph, 1024 );
  if ( strlen( $line ) <= 1 ) {
    continue;
  }
  $line = preg_replace( "/^(\S+).*/",
      "<a href=\"mailto:$1@$host\">$1</a><br />\n",
      $line );
  print "$line";
}
pclose( $ph );
?>
</div>
</body>
</html>
  
  








Related examples in the same category

1.Using popen() and pclose()
2.Using popen() to Pass Data to the column Application
3.Using popen() with nsupdate
4.Reading output from popen()
5.Opening a Process File Pointer with popen()
6.Opening a Unidirectional Pipe Using popen()
7.Redirecting standard output
8.Reading standard error