next up previous contents index
Next: POpen Up: Functions and procedures Previous: MkFifo

AssignStream

   

Declaration:

Procedure AssignStream (StreamIn,StreamOut : Text; Const prog : String) ;

Description:

AssignStream creates a 2 pipes, i.e. two file objects, one for input, one for output, the other ends of these pipes are connected to standard input and and output of Prog. Prog is the name of a program (including path) with options, which will be executed. What is written to StreamOut, will go to the standard input of Prog. Whatever is written by Prog to it's standard output be read from StreamIn. Reading and writing happens through the usual Readln(StreamIn,...) and Writeln (StreamOut,...) procedures.

Errors:

LinuxError is used to report errors:

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

Other errors include the ones by the fork and exec programs

See also:

AssignPipe, POpen,pipe (2)

Example
Program Example38;

{ Program to demonstrate the AssignStream function. }

Uses linux;

Var Si,So : Text;
    S : String;
    i : longint;
        
begin
  if not (paramstr(1)='-son') then
    begin
    Writeln ('Calling son');
    Assignstream (Si,So,'./ex38a -son');
    if linuxerror<>0 then writeln ('AssignStream failed !');
{$i-}
{    rewrite (so);
    if ioresult<>0 then writeln ('Error !!');
    reset(si);
    if ioresult<>0 then writeln ('Error !!');
 }   Writeln ('Speaking to son');
    For i:=1 to 10 do writeln (so,'Hello son !');
    For i:=1 to 3 do writeln (so,'Hello chap !');
    flush (so);
    while not eof(si) do
      begin
      readln (si,s);
      writeln ('Father: Son said : ',S);
      end;
    Writeln ('Stopped conversation');
    Close (Si);
    Close (so);
    Writeln ('Put down phone');
    end
  Else
    begin
    Writeln ('This is the son ');
    While not eof (input) do 
      begin
      readln (s);
      if pos ('Hello son !',S)<>0 then
         Writeln ('Hello Dad !')
      else 
         writeln ('Who are you ?');
      end
    end 
end.



Michael Van Canneyt
Tue Mar 31 16:46:10 CEST 1998