Assign stream for in and output to a program.
Source position: unix.pp line 157
function AssignStream( |
var StreamIn: text; |
var Streamout: text; |
const Prog: ansiString; |
const args: array of ansistring |
):cint; |
var StreamIn: text; |
var Streamout: text; |
var streamerr: text; |
const Prog: ansiString; |
const args: array of ansistring |
):cint; |
AssignStream creates a 2 or 3 pipes, i.e. two (or three) file objects, one for input, one for output,(and one for standard error) the other ends of these pipes are connected to standard input and output (and standard error) of Prog. Prog is the path of a program (including path). The options for the program can be specified in Args.
What is written to StreamOut, will go to the standard input of Prog. Whatever is written by Prog to it's standard output can be read from StreamIn. Whatever is written by Prog to it's standard error read from StreamErr, if present.
Reading and writing happens through the usual Readln(StreamIn,...) and Writeln (StreamOut,...) procedures.
Remark: | You should not use Reset or Rewrite on a file opened with POpen. This will close the file before re-opening it again, thereby closing the connection with the program. |
The function returns the process ID of the spawned process, or -1 in case of error.
Extended error information is returned by the FpGetErrno function.
Other errors include the ones by the fork and exec programs
|
Create a set of pipe file handlers. |
|
|
Pipe file to standard input/output of program. |
Program Example38; { Program to demonstrate the AssignStream function. } Uses BaseUnix,Unix; Var Si,So : Text; S : String; i : longint; begin if not (paramstr(1)='-son') then begin Writeln ('Calling son'); Assignstream (Si,So,paramstr(0),['-son']); if fpgeterrno<>0 then begin writeln ('AssignStream failed !'); halt(1); end; Writeln ('Speaking to son'); or:=1 to 10 do begin writeln (so,'Hello son !'); if ioresult<>0 then writeln ('Can''t speak to son...'); end; or:=1 to 3 do writeln (so,'Hello chap !'); close (so); while not ofi) do begin readln (si,s); writeln ('Father: Son said : ',S); end; Writeln ('Stopped conversation'); Close (Si); Writeln ('Put down phone'); end Else begin Writeln ('This is the son '); While not ofinput) do begin readln (s); if pos ('Hello son !',S)<>0 then Writeln ('Hello Dad !') else writeln ('Who are you ?'); end; close (output); end end.