Annotation of Examples/UNIX/Subprocess/Subprocess.rtf, revision 1.1.1.1

1.1       root        1: {\rtf0\ansi{\fonttbl\f0\froman Times;\f1\fmodern Courier;\f2\ftech Symbol;\f3\fmodern Ohlfs;}
                      2: \paperw12580
                      3: \paperh12200
                      4: \margl120
                      5: \margr120
                      6: {\colortbl\red0\green0\blue0;}
                      7: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs24 for Release 2.0  written by C. L. Oei, NeXT Computer, Inc.\
                      8: 
                      9: \b\fs16\li200 \
                     10: \
                     11: \
                     12: 
                     13: \fs36 Subprocess\
                     14: 
                     15: \fs16 \
                     16: 
                     17: \pard\tx6240\b0\fs30\li1200 INHERITS FROM      Object\
                     18: 
                     19: \fs16 \
                     20: 
                     21: \fs30 REQUIRES HEADER FILES    Subprocess.h\
                     22: \
                     23: DEFINED IN     NextDeveloper/Examples/Subprocess,\
                     24:        release 2.0\
                     25: 
                     26: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fs16\li1200 \
                     27: \
                     28: \
                     29: 
                     30: \fs30 CLASS DESCRIPTION\
                     31: 
                     32: \fs16 \
                     33: 
                     34: \fs30\li1660 Subprocess facilitates the management of concurrent, asynchronous UNIX processes within a NeXTstep application.  Methods are provided for the creation, termination and communication with the underlying UNIX process.  The UNIX subprocess communicates with its parent NeXTstep application through delegation.  Three delegate methods provide notification of pending output, termination and errors from the UNIX subprocess.  It is the responsibility of the Subprocess instantiator to implement the three delegate methods and decide what to do with the resulting data.  In addition to providing a controlled NeXTstep interface to standard UNIX utilities (i.e., 
                     35: \f1\fs24 ls, find, man,rdist
                     36: \f0\fs30 ), the Subprocess can also provide, on request, the environment necessary for UNIX processes requiring pseudo terminal (or 
                     37: \i pty
                     38: \i0 ) support.  Some UNIX applications that require pty support include 
                     39: \f1\fs24 ftp, gdb, sh, csh, kermit,
                     40: \f0\fs30  and 
                     41: \f1\fs24 tip
                     42: \f0\fs30 .\
                     43: 
                     44: \fs16\li1700 \
                     45: 
                     46: \li1200 \
                     47: \
                     48: 
                     49: \fs30 INSTANCE VARIABLES\
                     50: 
                     51: \fs16 \
                     52: 
                     53: \pard\tx6240\tx6740\tx9260\tx9760\i\fs30\fi-4540\li6240 Inherited from Object
                     54: \i0    Class   isa;\
                     55: 
                     56: \fs16 \
                     57: 
                     58: \i\fs30 Declared in Subprocess
                     59: \i0    id              delegate;\
                     60:        FILE    *fpToChild;\
                     61:        
                     62: \fc0 int               fromChild;\
                     63:        int             childPid;\
                     64: 
                     65: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fs16\fi-4540\li6240 \
                     66: 
                     67: \pard\tx6240\tx6740\tx9260\tx9760\fs30\fi-4540\li6240 delegate         The object that receives notification messages from the Subprocess.\
                     68: 
                     69: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fs16\fi-4540\li6240 \
                     70: 
                     71: \pard\tx6240\tx6740\tx9260\tx9760\fs30\fi-4540\li6240 fpToChild        File pointer to the standard input of the child subprocess.\
                     72: 
                     73: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fs16\fi-4540\li6240 \
                     74: 
                     75: \pard\tx6240\tx6740\tx9260\tx9760\fs30\fi-4540\li6240 fromChild        File descriptor from the standard output of the child subprocess.\
                     76: 
                     77: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fs16\fi-4540\li6240 \
                     78: 
                     79: \pard\tx6240\tx6740\tx9260\tx9760\fs30\fi-4540\li6240 childPid         The process id number of the child subprocess.\
                     80: 
                     81: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fs16\fi-4540\li6240 \
                     82: 
                     83: \fi0\li1200 \
                     84: \
                     85: 
                     86: \fs30 METHOD TYPES\
                     87: 
                     88: \fs16 \
                     89: 
                     90: \pard\tx6240\tx6740\tx9260\tx9760\fs30\fi-4540\li6240 Initializing a Subprocess        
                     91: \f2 - 
                     92: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\li1200 init
                     93: \pard\tx6240\tx6740\tx9260\tx9760\fi-4540\li6240 :\
                     94: 
                     95: \f2    - 
                     96: \f0 init:withDelegate:andPtySupport:andStdError:\
                     97: 
                     98: \fs16 \
                     99: 
                    100: \fs30 Terminating a Subprocess 
                    101: \f2 - 
                    102: \f0 terminate:\
                    103: 
                    104: \fs16 \
                    105: 
                    106: \fs30 Sending Data to a Subprocess     
                    107: \f2 - 
                    108: \f0 send: \
                    109: 
                    110: \f2    - 
                    111: \f0 send:withNewline:\
                    112: 
                    113: \f2    - 
                    114: \f0 terminateInput\
                    115: 
                    116: \fs16 \
                    117: 
                    118: \fs30 Assigning a Delegate     
                    119: \f2 - 
                    120: \f0 setDelegate: \
                    121: 
                    122: \f2    - 
                    123: \f0 delegate \
                    124: 
                    125: \fs16 \
                    126: 
                    127: \fs30 Messages Implemented by the Delegate\
                    128:        
                    129: \f2 - 
                    130: \f0 subprocessDone\
                    131: 
                    132: \f2    - 
                    133: \f0 subprocessError: \
                    134: 
                    135: \f2    - 
                    136: \f0 subprocessOutput: \
                    137: 
                    138: \fs16 \
                    139: 
                    140: \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\li1200 \
                    141: \
                    142: 
                    143: \fs30 INSTANCE METHODS\
                    144: 
                    145: \fs16 \
                    146: 
                    147: \b \
                    148: 
                    149: \fs30 init
                    150: \fs32 :\
                    151: 
                    152: \f2\b0\fs30\fi-1020\li2720 - 
                    153: \f0\b\fi0\li1200 init
                    154: \fi-1020\li2720 :
                    155: \b0 (const char *)
                    156: \i subprocessString
                    157: \i0 \
                    158: 
                    159: \fi0\li0 \
                    160: 
                    161: \li1700 Spawns the subprocess as specified in 
                    162: \i subprocessString
                    163: \i0 .  This method applies the 
                    164: \b init:withDelegate:andPtySupport:andStdError:
                    165: \b0  method with no delegate, no pseudo terminal support, and requests that standard error for the subprocess be returned with the standard output buffer
                    166: \fs32 .
                    167: \fs16 \
                    168: 
                    169: \fs30 \
                    170: See also:  
                    171: \f2\fi-1020\li2720 -
                    172: \f0\fi0\li1700  
                    173: \b\li1200 init:withDelegate:andPtySupport:andStdError
                    174: \li1700 :, 
                    175: \b0 � 
                    176: \b terminate:
                    177: \b0 \
                    178: 
                    179: \b\fs16\fi-1020\li2720 \
                    180: 
                    181: \b0\fs30\fi0\li1200 \
                    182: 
                    183: \b init:withDelegate:andPtySupport:andStdError
                    184: \fs32 :\
                    185: 
                    186: \f2\b0\fs30\fi-1020\li2720 - 
                    187: \f0\b\fi0\li1200 init
                    188: \fi-1020\li2720 :
                    189: \b0 (const char *)
                    190: \i subprocessString
                    191: \i0 \
                    192:     
                    193: \b withDelegate:
                    194: \b0\i theDelegate
                    195: \i0 \
                    196:     
                    197: \b andPtySupport:
                    198: \b0 (BOOL)
                    199: \i wantsPty
                    200: \i0 \
                    201:     
                    202: \b andStdErr:
                    203: \b0 (BOOL)
                    204: \i wantsStdErr
                    205: \i0 ;
                    206: \f2 \
                    207: 
                    208: \f0\fi0\li0 \
                    209: 
                    210: \li1700 Spawns the subprocess as specified in 
                    211: \i subprocessString
                    212: \i0  as a separate UNIX process and attaches the subprocess' standard input and standard output to the Subprocess instance for future operations.  If 
                    213: \i wantsStdErr
                    214: \i0  is YES, then the subprocess' standard error will be returned with the standard output buffer.  Set 
                    215: \i wantsPty
                    216: \i0  to YES if the UNIX subprocess requires pseudo terminal support (see the UNIX manual page 
                    217: \i pty(4)
                    218: \i0  for more information on pseudo terminals).  
                    219: \i TheDelegate
                    220: \i0  should be able to respond to any of the three methods described below.\
                    221: \
                    222: See also:  
                    223: \f2\fi-1020\li2720 -
                    224: \f0\fi0\li1700  
                    225: \b\li1200 init:, 
                    226: \b0\li1700 � 
                    227: \b terminate:
                    228: \b0 \
                    229: 
                    230: \b\fs16\fi-1020\li2720 \
                    231: 
                    232: \b0\fs30\fi0\li1200 \
                    233: \
                    234: INSTANCE METHODS\
                    235: 
                    236: \fs16 \
                    237: 
                    238: \b \
                    239: 
                    240: \fs32 delegate\
                    241: 
                    242: \f2\b0\fs30\fi-1020\li2720 - 
                    243: \f0\b\fi0\li0 delegate
                    244: \b0\i\fi-1020\li2720 \
                    245: 
                    246: \fs16 \
                    247: 
                    248: \i0\fs30\fi0\li1700 Returns the Subprocess object's delegate.\
                    249: \
                    250: See also:  � 
                    251: \b setDelegate:
                    252: \b0 \
                    253: 
                    254: \fs16 \
                    255: 
                    256: \b\li1200 \
                    257: 
                    258: \fs32 send:withNewline:\
                    259: 
                    260: \f2\b0\fs30\fi-1020\li2720 - 
                    261: \f0 (BOOL)
                    262: \b\fi0\li0 send:
                    263: \b0 (const char *)
                    264: \i string
                    265: \i0  
                    266: \b withNewline:
                    267: \b0 (BOOL)
                    268: \i wantNewline
                    269: \i0\fi-1020\li2720 \
                    270: 
                    271: \b\fs16 \
                    272: 
                    273: \b0\fs30\fi0\li1700 Sends 
                    274: \i string
                    275: \i0  to the UNIX subprocess.  If 
                    276: \i\li0 wantNewline
                    277: \i0\li1700  is YES, a newline is also sent to the subprocess. 
                    278: \fs16 \
                    279: 
                    280: \fs30 \
                    281: See also:  � 
                    282: \b send:
                    283: \b0 \
                    284: 
                    285: \b\fs16\li1200 \
                    286: \
                    287: 
                    288: \fs32 send:\
                    289: 
                    290: \f2\b0\fs30\fi-1020\li2720 - 
                    291: \f0\b\fi0\li0 send:
                    292: \b0 (const char *)
                    293: \i string
                    294: \i0\fi-1020\li2720 \
                    295: 
                    296: \fs16 \
                    297: 
                    298: \fs30\fi0\li1700 Sends 
                    299: \i string
                    300: \i0  to the UNIX subprocess automatically appending a newline.  This method applies the 
                    301: \b\fs32 send:withNewline:
                    302: \b0  method.
                    303: \fs16 \
                    304: 
                    305: \fs30 \
                    306: See also:  � 
                    307: \b send:withNewline:
                    308: \b0 \
                    309: 
                    310: \b\fs16\li1200 \
                    311: \
                    312: 
                    313: \fs32 setDelegate:\
                    314: 
                    315: \f2\b0\fs30\fi-1020\li2720 - 
                    316: \f0\b setDelegate:
                    317: \b0\i anObject\
                    318: 
                    319: \fs16 \
                    320: 
                    321: \i0\fs30\fi0\li1700 Makes 
                    322: \i anObject
                    323: \i0  the Subprocess' delegate.  The delegate should be able to (but is not necessarily required to) respond to the messages 
                    324: \b subprocessDone
                    325: \b0 , 
                    326: \b subprocessError:
                    327: \b0 , and
                    328: \f2  
                    329: \f0\b subprocessOutput:
                    330: \b0 .  See methods implemented by the delegate below.\
                    331: \
                    332: See also:  � 
                    333: \b delegate:
                    334: \b0 \
                    335: 
                    336: \fs16 \
                    337: 
                    338: \b\li1200 \
                    339: 
                    340: \fs32 terminate:\
                    341: 
                    342: \f2\b0\fs30\fi-1020\li2720 - 
                    343: \f0\b\fi0\li0 terminate:
                    344: \b0\i sender
                    345: \i0\fi-1020\li2720 \
                    346: 
                    347: \fs16 \
                    348: 
                    349: \fs30\fi0\li1700 Forces the subprocess to terminate gracefully.  Closes all communication connections to the subprocess and sends a terminate signal (SIGTERM) to the subprocess.  Sending this message implies sending the 
                    350: \b terminateInput
                    351: \b0  message.\
                    352: \
                    353: You should terminate a subprocess instance before your application terminates.  One way would be to override the Application object's delegate 
                    354: \b appWillTerminate:
                    355: \b0  method with an intervening message to terminate the subprocess object.\
                    356: \
                    357: Sending 
                    358: \b\li0 terminate:
                    359: \b0\li1700  multiple times will not cause 
                    360: \li0\fc0 undesirable
                    361: \li1700  effects.\
                    362: \
                    363: See also:  � 
                    364: \b\fs32\li1200 terminateInput, subprocessDone:
                    365: \b0\fs30\li1700 \
                    366: 
                    367: \fs16 \
                    368: 
                    369: \b\li1200 \
                    370: 
                    371: \fs32 terminateInput\
                    372: 
                    373: \f2\b0\fs30\fi-1020\li2720 - 
                    374: \f0\b\fi0\li0 terminateInput
                    375: \b0\i\fi-1020\li2720 \
                    376: 
                    377: \fs16 \
                    378: 
                    379: \i0\fs30\fi0\li1700 Closes the standard input communication connection to the subprocess, which effectively sends an end-of-file (EOF) to the subprocess.\
                    380: 
                    381: \fs16 \
                    382: 
                    383: \b\li1200 \
                    384: \
                    385: 
                    386: \b0\fs30 METHODS IMPLEMENTED BY THE DELEGATE\
                    387: 
                    388: \fs16 \
                    389: 
                    390: \b \
                    391: 
                    392: \fs32 subprocessDone:\
                    393: 
                    394: \f2\b0\fs30\fi-1020\li2720 - 
                    395: \f0\b subprocessDone
                    396: \b0\i \
                    397: 
                    398: \fs16 \
                    399: 
                    400: \i0\fs30\fi0\li1700 Sent to the delegate, if any, when the subprocess has terminated.  You will have to decide whether termination of the subprocess warrants the termination of your application.  Implies that the actions of sending a 
                    401: \b terminate:
                    402: \b0  message has completed.\
                    403: \
                    404: See also:  � 
                    405: \b terminate:
                    406: \b0 \
                    407: 
                    408: \fs16 \
                    409: 
                    410: \b\li1200 \
                    411: 
                    412: \fs32 subprocessError:\
                    413: 
                    414: \f2\b0\fs30\fi-1020\li2720 - 
                    415: \f0\b\fi0\li0 subprocessOutput:
                    416: \b0 (const char *)
                    417: \i errorString
                    418: \i0 ;
                    419: \fi-1020\li2720 \
                    420: 
                    421: \fs16 \
                    422: 
                    423: \fs30\fi0\li1700 Sent to the delegate, if any, when a fatal error occurs during the management of the subprocess.  If a fatal error occurs, it is usually during subprocess creation.  It is up to the delegate to decide if an error warrants termination of the application. Possible errors include, but are not limited to\
                    424: \
                    425:        � "
                    426: \li0 Error grabbing ptys for subprocess."
                    427: \li1700 \
                    428:        � 
                    429: \li0 "Error starting UNIX pipes to subprocess."
                    430: \li1700 \
                    431:        � 
                    432: \li0 "Error starting UNIX vfork of subprocess."
                    433: \li1700 \
                    434: 
                    435: \fs16 \
                    436: 
                    437: \b\li1200 \
                    438: 
                    439: \fs32 subprocessOutput:\
                    440: 
                    441: \f2\b0\fs30\fi-1020\li2720 - 
                    442: \f0\b\fi0\li0 subprocessOutput:
                    443: \b0 (char *)
                    444: \i buffer
                    445: \i0 ;
                    446: \fi-1020\li2720 \
                    447: 
                    448: \fs16 \
                    449: 
                    450: \fs30\fi0\li1700 Sent to the delegate, if any, when there is output data available from the subprocess.  
                    451: \i Buffer
                    452: \i0  is only valid until the next time a 
                    453: \b subprocessOutput: 
                    454: \b0 message is sent, so make a copy of 
                    455: \i buffer
                    456: \i0  if future processing is necessary.  You should choose carefully when deciding whether or not to send a 
                    457: \b send:
                    458: \b0  message to the subprocess in this delegate method implementation.  Sending a message may create a deadlock situation in your application. \
                    459: 
                    460: \fs16 \
                    461: \
                    462: 
                    463: \b\li1200 \
                    464: 
                    465: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.