home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
- Subprocess.h
-
- From Subprocess example by Charles L. Oei
- pty support by Joe Freeman
- with encouragement from Kristofer Younger
- Subprocess Example, Release 2.0
- NeXT Computer, Inc.
-
- You may freely copy, distribute and reuse the code in this example.
- NeXT disclaims any warranty of any kind, expressed or implied, as to
- its fitness for any particular use.
-
- This subprocess object sends/receives data to/from any UNIX
- subprocess asynchronously (via vfork/pipe).
- Its delegate, if any, will receive the following messages:
-
- - subprocess:sender done:(int)exitStatus;
- sent when the subprocess exits
-
- - subprocess:sender output:(char *)buffer;
- sent whenever there is data on the standard output pipe;
- buffer is only valid until next call
-
- - subprocess:sender stderrOutput:(char *)buffer;
- sent whenever there is data on the standard error pipe;
- buffer is only valid until next call.
-
- - subprocess:sender error:(const char *)errorString;
- sent when an error occurs;
- if it ever happens, it's usually only at startup time
-
- REVISIONS
- $Log$
- ----------------------------------------------------------------------------*/
- # import <stdio.h>
- # import <objc/Object.h>
-
- # define SUBPROCESS_STOPPED -1
- # define SUBPROCESS_SIGNALED -2
-
- @interface Subprocess:Object
- { FILE *fpToChild;
- FILE *fpFromChild;
- int fromChild;
- int stderrFromChild;
- int childPid;
- id delegate;
- char outputBuffer[BUFSIZ];
- int outputBufferLen;
- int stderrBufferLen;
- char stderrBuffer[BUFSIZ];
- BOOL paused;
- BOOL running;
- }
-
- - init:(const char *)subprocessString;
- - init:(const char *)subprocessString withDelegate:theDelegate;
- - setDelegate:anObject;
- - delegate;
- - send:(const char *)string withNewline:(BOOL)wantNewline;
- - send:(const char *)string;
- - (int)pid;
- - (BOOL)isPaused;
- - pause:sender;
- - resume:sender;
- - (BOOL)isRunning;
- - terminate:sender;
- - terminateInput;
-
- @end
-
- @interface Object(SubprocessDelegate)
-
- - subprocess:sender done:(int)exitStatus;
- - subprocess:sender output:(char *)buffer;
- - subprocess:sender stderrOutput:(char *)buffer;
- - subprocess:sender error:(const char *)errorString;
-
- @end
-