Sign in Join
FPDoc Onlineexperiment

AssignPipe function

In unit Unix

Create a set of pipe file handlers.

Declaration

pascal
function AssignPipe(var pipe_in: cint; var pipe_out: cint): cint

Description

AssignePipe creates a pipe, i.e. two file objects, one for input, one for output. What is written to Pipe_out, can be read from Pipe_in.

This call is overloaded. The in and out pipe can take three forms: an typed or untyped file, a text file or a file descriptor.

If a text file is passed then reading and writing from/to the pipe can be done through the usual Readln(Pipe_in,...) and Writeln(Pipe_out,...) procedures.

The function returns True if everything went successfully, False otherwise.

Errors

In case the function fails and returns False, extended error information is returned by the FpGetErrno function:

sys_emfile
Too many file descriptors for this process.
sys_enfile
The system file table is full.

See also

Example: ex36

pascal
Program Example36;

{ Program to demonstrate the AssignPipe function. }

Uses BaseUnix,Unix;

Var pipi,pipo : Text;
    s : String;

begin
  Writeln ('Assigning Pipes.');
  If assignpipe(pipi,pipo)<>0 then
    Writeln('Error assigning pipes !',fpgeterrno);
  Writeln ('Writing to pipe, and flushing.');
  Writeln (pipo,'This is a textstring');close(pipo);
  Writeln ('Reading from pipe.');
  While not eof(pipi) do
    begin
    Readln (pipi,s);
    Writeln ('Read from pipe : ',s);
    end;
  close (pipi);
  writeln ('Closed pipes.');
  writeln
end.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.