with Ada.IO_Exceptions, Interfaces.C, POSIX.IO;

with Open_Process, Close_Process;

procedure Demonstrate_Open_Process is
   File  : POSIX.IO.File_Descriptor;
   Line  : POSIX.IO.IO_Buffer (1 .. 100);
   Last  : Natural;
begin
   File := Open_Process ("who | sort", POSIX.IO.Read_Only);
   loop
      begin
         POSIX.IO.NONSTANDARD_Read (File   => File,
                                    Buffer => Line,
                                    Last   => Last);
         POSIX.IO.NONSTANDARD_Write (File   => POSIX.IO.Standard_Output,
                                     Buffer => Line (1 .. Last),
                                     Last   => Last);
      exception
         when Ada.IO_Exceptions.End_Error => exit;
         when others                      => raise;
      end;
   end loop;
   Close_Process (File);
end Demonstrate_Open_Process;

