UnixSpawnTCP.mesa
Copyright Ó 1989, 1990, 1991 by Xerox Corporation. All rights reserved.
Jules Bloomenthal August 23, 1992 1:13 pm PDT
DIRECTORY CedarProcess, IO, Rope, UnixTypes;
UnixSpawnTCP: CEDAR DEFINITIONS
~ BEGIN
Spawn a Unix Process
This uses tcp to transfer characters, whereas UnixSpawn uses the usually slower tty.
FinishProc:   TYPE ~ PROC [status: ATOM --$NotFound, $Completed--, clientData: REF ANY];
SpawnData:  TYPE ~ RECORD [
fd1, fd2:     UnixTypes.FileDescriptor, -- stdout or stderr
fdOut:     UnixTypes.FileDescriptor, -- stdout
pid:      INT,       -- process id, for abort
readOut:     CedarProcess.ForkableProc, -- procedure forked for read stdout
watch1, watch2:   CedarProcess.Process,  -- forked read process for fd1, fd2
readOutProcess:   CedarProcess.Process,  -- forked read process for stdout
finish:     FinishProc,     -- called upon completion of Unix process
clientData:    REF ANY,     -- passed to finish
out, err:     IO.STREAM];     -- out and err Cedar streams
Spawn: PROC [
command: Rope.ROPE,
out, err: IO.STREAM ¬ NIL,
finish: FinishProc ¬ NIL,
readOut: CedarProcess.ForkableProc ¬ NIL,
clientData: REF ANY ¬ NIL]
RETURNS [REF SpawnData];
command given to /bin/sh; NIL returned if error connecting to stdout or stderr.
command's stderr sent to err; stdout sent to out if NIL readOut.
If readOut non-NIL, it is expected to read s.fdOut; see implementation (ReadOut) for template.
finish, if non-NIL, called upon command completion and passed clientData.
Kill: PROC [s: REF SpawnData];
Kill the spawned Unix process.
Write: PROC [s: REF SpawnData, rope: Rope.ROPE];
Write to stdin associated with the Unix process the given rope.
Close: PROC [s: REF SpawnData];
Close the Unix process's stdin with an end-of-stream.
END.