This is MiscSubprocess.h in view mode; [Download] [Up]
//
// MiscSubprocess.h -- a Obj-C wrapper around Unix child processes
// Originally written by Drew Davidson
// Copyright (c) 1994 by Drew Davidson.
// Modified by Don Yacktman for inclusion into the MiscKit.
// Fixed up by Carl Lindberg, Don Yacktman, and Steve Hayman.
// Version 1.3. All rights reserved.
// This notice may not be removed from this source code.
//
// This object is included in the MiscKit by permission from the author
// and its use is governed by the MiscKit license, found in the file
// "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
// for a list of all applicable permissions and restrictions.
//
/*----------------------------------------------------------------------------
$Source$
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)status :(MiscSubprocessEndCode)code;
Sent when the subprocess exits. If code indicates what status
will be:
Misc_Exited
status is the exit code returned by the process.
Misc_Stopped
status is the signal that caused the subprocess
to stop.
Misc_Signaled
status is the signal that caused the subprocess to
terminate
Misc_UnknownEndCode
status == 0.
- subprocess:sender output:(NSString *)output;
sent whenever there is data on the standard output pipe;
buffer is only valid until next call
- subprocess:sender outputData:(NSData *)output;
sent whenever there is data on the standard output pipe;
buffer is only valid until next call
- subprocess:sender stderrOutput:(NSString *)output;
sent whenever there is data on the standard error pipe;
buffer is only valid until next call.
- subprocess:sender stderrOutputData:(NSData *)output;
sent whenever there is data on the standard error pipe;
buffer is only valid until next call.
- subprocess:sender error:(NSString *)errorString;
sent when an error occurs;
if it ever happens, it's usually only at startup time
(has nothing to do with errors in the subprocess, but
rather in starting/stopping/etc. the process)
The object keeps a NSMutableDictionary of strings to be used as the
environment for the exec'd subprocess. It is accessible through
the environment method.
REVISIONS
$Log$
----------------------------------------------------------------------------*/
#import <foundation/NSObject.h>
#import <stdio.h> // For FILE
typedef enum
{
Misc_Exited,
Misc_Stopped,
Misc_Signaled,
Misc_UnknownEndCode
} MiscSubprocessEndCode;
@class NSMutableDictionary;
@interface MiscSubprocess:NSObject
{
id delegate;
NSMutableDictionary *environment;
NSString *execArg1;
NSString *execArg2;
NSString *execArg3;
FILE *fpToChild;
FILE *fpFromChild;
int stdoutFromChild;
int stderrFromChild;
int dpsStdoutFromChild;
int dpsStderrFromChild;
int childPid;
int masterPty;
int slavePty;
BOOL paused;
BOOL running;
BOOL usePtys;
BOOL asynchronous;
BOOL stdoutIsDone, stderrIsDone;
}
/*
* Designated initializer for MiscSubprocess. If aString is nil
* then nothing is executed. Normally you will want envFlag==YES, but
* we leave you the option, Just In Case(TM). If you use async=NO
* then we don't return until the subprocess exits.
*/
- init:(NSString *)aString
withDelegate:theDelegate
keepEnvironment:(BOOL)envFlag
withPtys:(BOOL)ptyFlag
asynchronously:(BOOL)async;
/*
* Externally callable routine to initiate the execution of
* the command aString.
*/
- execute:(NSString *)aString withPtys:(BOOL)ptyFlag asynchronously:(BOOL)async;
/*
* Called by execute: to perform the exec function.
* Override to call something other than the default execle().
*/
- execChild:(NSString *)aString;
- setExecArgs:(NSString *)a0 :(NSString *)a1 :(NSString *)a2;
- setDelegate:anObject;
- delegate;
- environment;
- send:(NSString *)string withNewline:(BOOL)wantNewline;
- send:(NSString *)string;
- terminateInput;
- (int)pid;
- pause:sender;
- resume:sender;
- (BOOL)isPaused;
- (BOOL)isRunning;
// *DO NOT* send SIGSTOP or SIGCONT via this method -- use -pause: or -resume:
- sendSignal:(int)signalNum;
- terminate:sender;
- (BOOL)usePtys;
- setUsePtys:(BOOL)flag;
- (BOOL)asynchronous;
- setAsynchronous:(BOOL)flag;
/***************************/
/*** CONVENIENCE METHODS ***/
/***************************/
- init;
- init:(NSString *)aString;
- init:(NSString *)aString withDelegate:(id)theDelegate;
- init:(NSString *)aString keepEnvironment:(BOOL)envFlag;
- init:(NSString *)aString withDelegate:(id)theDelegate keepEnvironment:(BOOL)envFlag;
- init:(NSString *)aString withPtys:(BOOL)ptyFlag;
- init:(NSString *)aString withDelegate:(id)theDelegate withPtys:(BOOL)ptyFlag;
- init:(NSString *)aString keepEnvironment:(BOOL)envFlag withPtys:(BOOL)ptyFlag;
- init:(NSString *)aString withDelegate:(id)theDelegate keepEnvironment:(BOOL)envFlag withPtys:(BOOL)ptyFlag;
- init:(NSString *)aString asynchronously:(BOOL)async;
- init:(NSString *)aString withDelegate:(id)theDelegate asynchronously:(BOOL)async;
- init:(NSString *)aString keepEnvironment:(BOOL)envFlag asynchronously:(BOOL)async;
- init:(NSString *)aString withDelegate:(id)theDelegate keepEnvironment:(BOOL)envFlag asynchronously:(BOOL)async;
- init:(NSString *)aString withPtys:(BOOL)ptyFlag asynchronously:(BOOL)async;
- init:(NSString *)aString withDelegate:(id)theDelegate withPtys:(BOOL)ptyFlag asynchronously:(BOOL)async;
- init:(NSString *)aString keepEnvironment:(BOOL)envFlag withPtys:(BOOL)ptyFlag asynchronously:(BOOL)async;
- execute:(NSString *)aString;
- execute:(NSString *)aString withPtys:(BOOL)ptyFlag;
- execute:(NSString *)aString asynchronously:(BOOL)async;
@end
/*
@interface NSObject(MiscSubprocessDelegate)
- subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
- subprocess:sender output:(NSString *)output;
- subprocess:sender outputData:(NSData *)output;
- subprocess:sender stderrOutput:(NSString *)output;
- subprocess:sender stderrOutputData:(NSData *)output;
- subprocess:sender error:(NSString *)errorString;
@end
*/
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.