OSProcess.st
changeset 21172 36a0e5430705
parent 20379 135c4fc19014
child 21181 a8a9220ed86f
equal deleted inserted replaced
21171:42edbb750d4e 21172:36a0e5430705
     1 "{ Package: 'stx:libbasic' }"
     1 "{ Package: 'stx:libbasic' }"
     2 
     2 
     3 "{ NameSpace: Smalltalk }"
     3 "{ NameSpace: Smalltalk }"
     4 
     4 
     5 Object subclass:#OSProcess
     5 Object subclass:#OSProcess
     6 	instanceVariableNames:'pid parentPid commandLine'
     6 	instanceVariableNames:'pid parentPid command environment directory inStream outStream
       
     7 		errorStream exitStatus finishSema'
     7 	classVariableNames:''
     8 	classVariableNames:''
     8 	poolDictionaries:''
     9 	poolDictionaries:''
     9 	category:'System-Support'
    10 	category:'System-Support'
    10 !
    11 !
    11 
    12 
    30         Process
    31         Process
    31 
    32 
    32 "
    33 "
    33 ! !
    34 ! !
    34 
    35 
       
    36 !OSProcess class methodsFor:'initialize'!
       
    37 
       
    38 initialize
       
    39     "Backward compatibility"
       
    40     Win32Process := self.
       
    41 ! !
       
    42 
    35 !OSProcess methodsFor:'accessing'!
    43 !OSProcess methodsFor:'accessing'!
    36 
    44 
    37 accessor
    45 accessor
    38     ^ self
    46     ^ self
    39 !
    47 !
    40 
    48 
    41 commandLine
    49 command
    42     ^ commandLine
    50     "return the value of the instance variable 'command' (automatically generated)"
    43 !
    51 
    44 
    52     ^ command
    45 commandLine:something
    53 
    46     commandLine := something.
    54     "Created: / 10.11.1998 / 21:27:07 / cg"
       
    55 !
       
    56 
       
    57 command:something
       
    58     "set the value of the instance variable 'command' (automatically generated)"
       
    59 
       
    60     command := something.
       
    61 
       
    62     "Created: / 10.11.1998 / 21:27:07 / cg"
       
    63 !
       
    64 
       
    65 directory
       
    66     "return the value of the instance variable 'directory' (automatically generated)"
       
    67 
       
    68     ^ directory
       
    69 
       
    70     "Created: / 10.11.1998 / 21:21:52 / cg"
       
    71 !
       
    72 
       
    73 directory:something
       
    74     "set the value of the instance variable 'directory' (automatically generated)"
       
    75 
       
    76     directory := something.
       
    77 
       
    78     "Created: / 10.11.1998 / 21:21:52 / cg"
       
    79 !
       
    80 
       
    81 environment
       
    82     "return the value of the instance variable 'environment' (automatically generated)"
       
    83 
       
    84     ^ environment
       
    85 
       
    86     "Created: / 10.11.1998 / 21:26:34 / cg"
       
    87 !
       
    88 
       
    89 environment:something
       
    90     "set the value of the instance variable 'environment' (automatically generated)"
       
    91 
       
    92     environment := something.
       
    93 
       
    94     "Created: / 10.11.1998 / 21:27:07 / cg"
       
    95 !
       
    96 
       
    97 errorStream
       
    98     "return the value of the instance variable 'errorStream' (automatically generated)"
       
    99 
       
   100     ^ errorStream
       
   101 
       
   102     "Created: / 10.11.1998 / 21:26:34 / cg"
       
   103 !
       
   104 
       
   105 errorStream:something
       
   106     "set the value of the instance variable 'errorStream' (automatically generated)"
       
   107 
       
   108     errorStream := something.
       
   109 
       
   110     "Created: / 10.11.1998 / 21:26:34 / cg"
       
   111 !
       
   112 
       
   113 exitStatus
       
   114     "return the value of the instance variable 'exitStatus' (automatically generated)"
       
   115 
       
   116     ^ exitStatus
       
   117 
       
   118     "Created: / 10.11.1998 / 21:24:55 / cg"
       
   119 !
       
   120 
       
   121 exitStatus:something
       
   122     "set the value of the instance variable 'exitStatus' (automatically generated)"
       
   123 
       
   124     exitStatus := something.
       
   125 
       
   126     "Created: / 10.11.1998 / 21:24:55 / cg"
       
   127 !
       
   128 
       
   129 finishSema
       
   130     "return the value of the instance variable 'finishSema' (automatically generated)"
       
   131 
       
   132     ^ finishSema
       
   133 
       
   134     "Created: / 10.11.1998 / 21:21:53 / cg"
       
   135 !
       
   136 
       
   137 finishSema:something
       
   138     "set the value of the instance variable 'finishSema' (automatically generated)"
       
   139 
       
   140     finishSema := something.
       
   141 
       
   142     "Created: / 10.11.1998 / 21:21:53 / cg"
       
   143 !
       
   144 
       
   145 inStream
       
   146     "return the value of the instance variable 'inStream' (automatically generated)"
       
   147 
       
   148     ^ inStream
       
   149 
       
   150     "Created: / 10.11.1998 / 21:26:34 / cg"
       
   151 !
       
   152 
       
   153 inStream:something
       
   154     "set the value of the instance variable 'inStream' (automatically generated)"
       
   155 
       
   156     inStream := something.
       
   157 
       
   158     "Created: / 10.11.1998 / 21:26:34 / cg"
       
   159 !
       
   160 
       
   161 outStream
       
   162     "return the value of the instance variable 'outStream' (automatically generated)"
       
   163 
       
   164     ^ outStream
       
   165 
       
   166     "Created: / 10.11.1998 / 21:26:34 / cg"
       
   167 !
       
   168 
       
   169 outStream:something
       
   170     "set the value of the instance variable 'outStream' (automatically generated)"
       
   171 
       
   172     outStream := something.
       
   173 
       
   174     "Created: / 10.11.1998 / 21:26:34 / cg"
    47 !
   175 !
    48 
   176 
    49 parentPid
   177 parentPid
    50     ^ parentPid
   178     ^ parentPid
    51 !
   179 !
    74     aStream 
   202     aStream 
    75         nextPutAll:self className;
   203         nextPutAll:self className;
    76         nextPut:$(.
   204         nextPut:$(.
    77     pid printOn:aStream.
   205     pid printOn:aStream.
    78     aStream space.
   206     aStream space.
    79     commandLine printOn:aStream.
   207     command printOn:aStream.
    80     aStream nextPut:$)
   208     aStream nextPut:$)
    81 ! !
   209 ! !
    82 
   210 
    83 !OSProcess methodsFor:'queries'!
   211 !OSProcess methodsFor:'queries'!
    84 
   212 
   100     "answer true, if the process is no longer alive"
   228     "answer true, if the process is no longer alive"
   101 
   229 
   102     ^ self isAlive not
   230     ^ self isAlive not
   103 ! !
   231 ! !
   104 
   232 
       
   233 !OSProcess methodsFor:'starting'!
       
   234 
       
   235 startProcess
       
   236     finishSema := Semaphore new.
       
   237 
       
   238     Processor 
       
   239         monitor:[
       
   240             pid := OperatingSystem
       
   241                 startProcess:command
       
   242                 inputFrom:inStream
       
   243                 outputTo:outStream
       
   244                 errorTo:errorStream
       
   245                 auxFrom:nil
       
   246                 environment:nil
       
   247                 inDirectory:directory
       
   248                 showWindow:false.
       
   249         ] 
       
   250         action:[:status |
       
   251             status stillAlive ifFalse:[
       
   252                 exitStatus := status.
       
   253                 "/ paranoia?
       
   254                 pid notNil ifTrue:[
       
   255                     OperatingSystem terminateProcessGroup:pid.
       
   256                     OperatingSystem terminateProcess:pid.
       
   257                     OperatingSystem closePid:pid.
       
   258                 ].
       
   259                 finishSema signal
       
   260             ].
       
   261         ].
       
   262 
       
   263     pid isNil ifTrue:[
       
   264         exitStatus := OperatingSystem osProcessStatusClass processCreationFailure.
       
   265         ^ false
       
   266     ].
       
   267 
       
   268     ^ true.
       
   269 
       
   270     "Created: / 10.11.1998 / 21:23:50 / cg"
       
   271     "Modified: / 10.11.1998 / 21:33:16 / cg"
       
   272 ! !
       
   273 
   105 !OSProcess methodsFor:'terminating'!
   274 !OSProcess methodsFor:'terminating'!
   106 
   275 
   107 kill
   276 kill
   108     "kill the process - the process does not get the chance to clean up"
   277     "kill the process - the process does not get the chance to clean up"
   109     
   278     
   150 
   319 
   151 version_CVS
   320 version_CVS
   152     ^ '$Header$'
   321     ^ '$Header$'
   153 ! !
   322 ! !
   154 
   323 
       
   324 
       
   325 OSProcess initialize!