[Overview][Constants][Types][Procedures and functions][Variables][Index] | Reference for unit 'Unix' (#rtl)

# AssignPipe

Create a set of pipe file handlers

## Declaration

Source position: unix.pp line 105

`function AssignPipe(`
`var pipe_in: cint;`
`var pipe_out: cint`
`):cint; function AssignPipe(`
`var pipe_in: text;`
`var pipe_out: text`
`):cint; function AssignPipe(`
`var pipe_in: file;`
`var pipe_out: file`
`):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

POpen |  | Pipe file to standard input/output of program
#rtl.baseunix.FpMkFifo |  | Create FIFO (named pipe) in file system

## Example

    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.