OSProcess.st
author Claus Gittinger <cg@exept.de>
Tue, 22 May 2018 12:24:27 +0200
changeset 22985 da550df21477
parent 22984 e8fd046ea3ba
child 22986 6574facad5bf
permissions -rw-r--r--
#FEATURE by cg class: OSProcess removed: #pid: comment/format in: #outStream #terminateActionBlock #terminateActionBlock: changed: #startProcess
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:libbasic' }"
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     2
19286
9e8eea97fd57 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
     3
"{ NameSpace: Smalltalk }"
9e8eea97fd57 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
     4
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
     5
Object subclass:#OSProcess
22984
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
     6
        instanceVariableNames:'pid command environment directory inStream outStream errorStream
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
     7
                auxStream showWindow lineWise newPgrp exitStatus finishSema
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
     8
                shufflerProcesses streamsToClose terminateActionBlock'
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
     9
        classVariableNames:''
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
    10
        poolDictionaries:''
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
    11
        category:'System-Support'
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    12
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    13
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    14
OSProcess subclass:#RemoteOSProcess
22984
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
    15
        instanceVariableNames:'host'
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
    16
        classVariableNames:'MethodPerHost'
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
    17
        poolDictionaries:''
e8fd046ea3ba #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22983
diff changeset
    18
        privateIn:OSProcess
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    19
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    20
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    21
!OSProcess class methodsFor:'documentation'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    22
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    23
documentation
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    24
"
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
    25
    Instances of OSProcess represent operating system processes that can be executed.
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    26
    (as opposed to Smalltalk processes).
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    27
    Both local and remote processes are suported.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    28
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    29
    commandString:
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    30
     If command is a String, the commandString is passed to a shell for execution
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    31
     - see the description of 'sh -c' in your UNIX manual ('cmd.exe' in your Windows manual).
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    32
     Regular input/output redirection and pipes etc. are supported as supported by
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    33
     the underlying OS's command interpreter (i.e. some limits apply to MSDOS)
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    34
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    35
     With an empty command, the shell will read commands from the passed input stream.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    36
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    37
     If command is an Array, the first element is the command to be executed,
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    38
     and the other elements are the arguments to the command. 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    39
     No shell is invoked in this case. Any redirection or piping can then be done
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    40
     by Smalltalk code (including piping through smalltalk streams & filters).
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    41
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    42
    [author:]
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    43
        Stefan Vogel (stefan@zwerg)
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    44
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    45
    [instance variables:]
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    46
        pid         SmallInteger    the process id
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
    47
        command     String          the command line of the running command.
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    48
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    49
    [class variables:]
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    50
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    51
    [see also:]
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    52
        Process
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    53
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    54
"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    55
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    56
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    57
examples
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
    58
"
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    59
  send command's output to the Transcript:
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    60
                                                            [exBegin]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    61
    OSProcess new 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    62
        command:'ls -l';
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    63
        outStream:Transcript;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    64
        lineWise:true;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    65
        execute.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    66
                                                            [exEnd]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    67
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    68
  send command's output to my stdout (see console):
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    69
                                                            [exBegin]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    70
    OSProcess new 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    71
        command:'ls -l';
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    72
        outStream:Stdout;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    73
        execute.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    74
                                                            [exEnd]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    75
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    76
  send command's output to a Smalltalk stream:
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
    77
                                                            [exBegin]
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    78
    |outStream|
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    79
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    80
    outStream := '' writeStream.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    81
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    82
    OSProcess new 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    83
        command:'ls -l';
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    84
        outStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    85
        execute.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    86
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    87
    outStream contents inspect.
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
    88
                                                            [exEnd]
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
    89
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    90
  feed it from a smalltalk stream, get command's output into a Smalltalk stream:
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    91
                                                            [exBegin]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    92
    |inStream outStream|
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    93
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    94
    inStream := 'hello world' readStream.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    95
    outStream := '' writeStream.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    96
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    97
    OSProcess new 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    98
        command:'tr ''a-z'' ''A-Z''';
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    99
        inStream:inStream;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   100
        outStream:outStream;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   101
        execute.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   102
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   103
    outStream contents inspect.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   104
                                                            [exEnd]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   105
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   106
  again, send output to a Smalltalk stream;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   107
  watch the stream getting filled after 10 seconds:
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   108
                                                            [exBegin]
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   109
    |outStream|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   110
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   111
    outStream := '' writeStream.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   112
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   113
    OSProcess new 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   114
        command:'ls -l; sleep 10; echo =================================; echo hallo after 10s; echo >&2 +++++++++++++++++++++; cat >&2';
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   115
        outStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   116
        errorStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   117
        startProcess.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   118
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   119
    outStream inspect
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   120
                                                            [exEnd]
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   121
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   122
  separate stdout and stderr:
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   123
                                                            [exBegin]
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   124
    |outStream errStream|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   125
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   126
    outStream := '' writeStream.
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   127
    errStream := '' writeStream.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   128
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   129
    OSProcess new 
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   130
        command:'ls -l && ls >&2';
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   131
        outStream:outStream;
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   132
        errorStream:errStream;
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   133
        startProcess.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   134
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   135
    outStream inspect.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   136
    errStream inspect.
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   137
                                                            [exEnd]
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   138
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   139
  Execute commands in shell/cmd.exe and read them from stdin:
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   140
                                                            [exBegin]
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   141
    |outStream|
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   142
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   143
    outStream := '' writeStream.
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   144
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   145
    OSProcess new 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   146
        command:'';
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   147
        inStream:'ls -l' readStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   148
        outStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   149
        lineWise:true;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   150
        execute.
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   151
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   152
    outStream contents inspect
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   153
                                                            [exEnd]
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   154
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   155
  Execute on a remote host (you must have the appropriate ssh setup):
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   156
                                                            [exBegin]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   157
    |outStream|
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   158
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   159
    outStream := '' writeStream.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   160
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   161
    (OSProcess onHost:'exeptn') 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   162
        command:'ls -l';
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   163
        outStream:outStream;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   164
        lineWise:true;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   165
        execute.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   166
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   167
    outStream contents inspect
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   168
                                                            [exEnd]
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   169
"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   170
! !
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   171
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   172
!OSProcess class methodsFor:'instance creation'!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   173
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   174
command:aCommandString
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   175
    "return an initialized instance to execute aCommandString
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   176
     in the current directory (for a local process)"
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   177
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   178
    ^ self new command:aCommandString.
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   179
!
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   180
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   181
command:aCommandString directory:aStringOrFilename
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   182
    "return an initialized instance to execute aCommandString 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   183
     in a given directory (for a local process)"
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   184
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   185
    ^ self new command:aCommandString directory:aStringOrFilename.
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   186
!
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   187
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   188
commandStringForProgramName:executableFile arguments:arrayOfStrings
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   189
    ^ String streamContents:[:s |
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   190
        s nextPutAll:(self possiblyQuoted:executableFile asFilename pathName).
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   191
        arrayOfStrings do:[:eachArg |
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   192
            s nextPutAll:(self possiblyQuoted:eachArg).
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   193
        ].
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   194
    ]
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   195
!
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   196
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   197
new
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   198
    "return an initialized instance for a local process"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   199
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   200
    ^ self basicNew initialize.
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   201
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   202
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   203
onHost:aHost
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   204
    "return an initialized instance for a remote process running on another host"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   205
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   206
    (SocketAddress hostName:aHost) isLocal ifTrue:[
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   207
        ^ self basicNew initialize.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   208
    ].
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   209
    ^ RemoteOSProcess basicNew host:aHost; initialize.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   210
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   211
    "
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   212
     OSProcess onHost:'localhost'
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   213
     OSProcess onHost:'exeptn'
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   214
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   215
     (OSProcess new) command:'ls'
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   216
     (OSProcess onHost:'exeptn') command:'ls'
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   217
    "
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   218
!
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   219
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   220
possiblyQuoted:aString
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   221
    "should we quote or escape?"
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   222
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   223
    ^ String streamContents:[:s |
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   224
        aString do:[:ch |
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   225
            (ch isSeparator or:[ch = $\]) ifTrue:[
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   226
                s nextPut:$\
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   227
            ].
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   228
            s nextPut:ch
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   229
        ]
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   230
    ]
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   231
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   232
    "
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   233
     self possiblyQuoted:'foo bar' 
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   234
     self possiblyQuoted:'foo\bar'
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   235
    "
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   236
!
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   237
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   238
programName:executableFile arguments:arrayOfStrings initialEnvironment:stringDictionary
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   239
    "similar to command:, but with separate command and arguments"
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   240
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   241
    ^ self new
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   242
        command:(self commandStringForProgramName:executableFile arguments:arrayOfStrings);
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   243
        environment:stringDictionary;
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   244
        yourself
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   245
! !
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   246
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   247
!OSProcess class methodsFor:'class initialization'!
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   248
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   249
initialize
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   250
    "Backward compatibility: Win32Process is an alias for OSProcess"
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   251
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   252
    Win32Process := self.
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   253
! !
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   254
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   255
!OSProcess class methodsFor:'queries'!
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   256
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   257
defaultShellPath
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   258
    OperatingSystem isUNIXlike ifTrue:[
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   259
        ^ OperatingSystem getEnvironment:'SHELL' 
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   260
    ].
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   261
    ^ 'cmd'
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   262
! !
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   263
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   264
!OSProcess methodsFor:'accessing'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   265
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   266
auxStream
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   267
    ^ auxStream
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   268
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   269
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   270
auxStream:something
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   271
    "set an auxiliary input stream that will be available to the command as
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   272
     file descriptor 3"
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   273
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   274
    auxStream := something.
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   275
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   276
    "Modified (comment): / 23-02-2017 / 10:56:57 / Maren"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   277
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   278
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   279
command
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   280
    "the OS (shell-) command"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   281
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   282
    ^ command
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   283
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   284
    "Created: / 10.11.1998 / 21:27:07 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   285
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   286
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   287
command:aStringOrArray 
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   288
    "set the command to be executed.
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   289
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   290
     If aStringOrArray is a String, the commandString is passed to a shell for execution
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   291
     - see the description of 'sh -c' in your UNIX manual ('cmd.exe' in your Windows manual).
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   292
     With an empty command, the shell will read commands from the passed input stream.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   293
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   294
     If aCommandString is an Array, the first element is the command to be executed,
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   295
     and the other elements are the arguments to the command. 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   296
     No shell is invoked in this case."
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   297
    
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   298
    command := aStringOrArray.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   299
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   300
22436
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   301
command:commandStringArg directory:stringOrFilenameArg
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   302
    "set the command to be executed and directory, where to execute.
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   303
     If aStringOrArray is a String, the commandString is passed to a shell for execution
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   304
     - see the description of 'sh -c' in your UNIX manual ('cmd.exe' in your Windows manual).
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   305
     If aCommandString is an Array, the first element is the command to be executed,
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   306
     and the other elements are the arguments to the command. No shell is invoked in this case."
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   307
22436
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   308
    command := commandStringArg.
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   309
    directory := stringOrFilenameArg.
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   310
!
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   311
22181
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   312
command:commandArg environment:environmentArg directory:directoryArg inStream:inStreamArg outStream:outStreamArg errorStream:errorStreamArg auxStream:auxStreamArg showWindow:showWindowArg lineWise:lineWiseArg 
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   313
    "set the command to be executed & directory, where to execute.
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   314
     and input/output streams.
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   315
     See comments in individual setters for more info"
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   316
22181
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   317
    command := commandArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   318
    environment := environmentArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   319
    directory := directoryArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   320
    inStream := inStreamArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   321
    outStream := outStreamArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   322
    errorStream := errorStreamArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   323
    auxStream := auxStreamArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   324
    showWindow := showWindowArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   325
    lineWise := lineWiseArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   326
!
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   327
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   328
directory
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   329
    "the directory where executed"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   330
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   331
    ^ directory
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   332
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   333
    "Created: / 10.11.1998 / 21:21:52 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   334
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   335
22436
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   336
directory:aStringOrFilename
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   337
    "set the directory that will be set as the current directory of the command to be executed"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   338
22436
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   339
    directory := aStringOrFilename.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   340
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   341
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   342
environment
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   343
    "the shell environment"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   344
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   345
    ^ environment
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   346
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   347
    "Created: / 10.11.1998 / 21:26:34 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   348
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   349
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   350
environment:aDictionary
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   351
    "set the environment variables of the command to be executed"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   352
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   353
    environment := aDictionary.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   354
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   355
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   356
errorStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   357
    ^ errorStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   358
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   359
    "Created: / 10.11.1998 / 21:26:34 / cg"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   360
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   361
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   362
errorStream:aStream
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   363
    "set the stream where the stderr output of the command is directed to"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   364
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   365
    errorStream := aStream.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   366
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   367
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   368
exitStatus
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   369
    "answer the exit status of the command or nil, if the command has not yet been finished"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   370
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   371
    ^ exitStatus
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   372
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   373
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   374
exitStatus:something
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   375
    "set the value of the instance variable 'exitStatus' (automatically generated)"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   376
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   377
    exitStatus := something.
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   378
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   379
    "Created: / 10.11.1998 / 21:24:55 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   380
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   381
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   382
finishSema
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   383
    "wait on this semaphore if you want to wait until the OS process has finished.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   384
     There may be multiple waiters, so it is a good idea to do a #waitUncounted"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   385
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   386
    ^ finishSema
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   387
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   388
    "Modified (comment): / 23-02-2017 / 10:53:17 / Maren"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   389
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   390
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   391
inStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   392
    ^ inStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   393
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   394
    "Created: / 10.11.1998 / 21:26:34 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   395
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   396
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   397
inStream:aStream
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   398
    "set the stream where the stdin input of the command is read from"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   399
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   400
    inStream := aStream.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   401
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   402
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   403
lineWise
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   404
    ^ lineWise
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   405
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   406
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   407
lineWise:aBoolean
21209
e9395c842124 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21208
diff changeset
   408
    "When setting to true, read linewise from the command's output and error.
e9395c842124 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21208
diff changeset
   409
     This is a bit slower than lineWise = false.
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   410
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   411
     You may use it also when streaming to e.g. Transcript"
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   412
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   413
    lineWise := aBoolean.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   414
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   415
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   416
newPgrp
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   417
    ^ newPgrp
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   418
!
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   419
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   420
newPgrp:aBoolean
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   421
    "if aBoolean is true, a new process group will be created for the command and its subprocesses"
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   422
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   423
    newPgrp := aBoolean.
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   424
!
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   425
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   426
outStream
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   427
    "the stream where the stdout output of the command is directed to"
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   428
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   429
    ^ outStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   430
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   431
    "Created: / 10.11.1998 / 21:26:34 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   432
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   433
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   434
outStream:aStream
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   435
    "set the stream where the stdout output of the command is directed to"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   436
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   437
    outStream := aStream.
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   438
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   439
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   440
pid
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   441
    "answer the pid of the process the command is running in or nil, if the command has not yet been started."
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   442
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   443
    ^ pid
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   444
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   445
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   446
showWindow
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   447
    ^ showWindow
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   448
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   449
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   450
showWindow:aBooleanOrNil
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   451
    "This parameter is ignored on Unix systems.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   452
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   453
     You can control (have to - sigh) if a window should be shown for the command or not.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   454
     This is the OS's H_SHOWWINDOW argument.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   455
     If you pass nil as showWindow-argument, the OS's default is used for the particular
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   456
     command, which is correct most of the time: i.e. a notepad will open its window, other (non-UI)
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   457
     executables will not.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   458
     However, some command-line executables show a window, even if they should not.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   459
     (and also, there seems to be an inconsistency between windows7 and newer windows: in newer,
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   460
     a shell command opens a cmd-window, whereas in windows7 it did not)
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   461
     In this case, pass an explicit false argument to suppress it."
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   462
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   463
    showWindow := aBooleanOrNil.
21206
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   464
!
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   465
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   466
terminateActionBlock
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   467
    "the (user provided) callback block,
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   468
     that will be executed when the command has finished or was terminated.
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   469
     If non-nil, it will be called with optional argument:status and:self, the OSProcess."
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   470
21206
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   471
    ^ terminateActionBlock
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   472
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   473
    "Modified (comment): / 22-05-2018 / 12:21:24 / Claus Gittinger"
21206
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   474
!
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   475
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   476
terminateActionBlock:aBlock
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   477
    "set the callback block,
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   478
     that will be called when the command has finished or was terminated.
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   479
     If non-nil, it will be called with optional argument:status and:self, the OSProcess."
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   480
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   481
    terminateActionBlock := aBlock.
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   482
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   483
    "Modified (comment): / 22-05-2018 / 12:21:12 / Claus Gittinger"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   484
! !
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   485
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   486
!OSProcess methodsFor:'initialization'!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   487
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   488
initialize
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   489
    "Invoked when a new instance is created."
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   490
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   491
    showWindow := false.    "/ for backward compatibility
21183
fdeb19204fb2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21182
diff changeset
   492
    lineWise := false.
fdeb19204fb2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21182
diff changeset
   493
    newPgrp := true.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   494
! !
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   495
13313
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   496
!OSProcess methodsFor:'printing'!
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   497
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   498
printOn:aStream
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   499
    aStream 
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   500
        nextPutAll:self className;
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   501
        nextPut:$(.
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   502
    pid printOn:aStream.
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   503
    aStream space.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   504
    command printOn:aStream.
13313
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   505
    aStream nextPut:$)
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   506
! !
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   507
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   508
!OSProcess methodsFor:'private'!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   509
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   510
setupShufflerForInput:aStream
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   511
    "if aStream is an internal Stream, set up a pipe for the command input.
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   512
     Start a process that shuffles the data from the internal stream into the pipe
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   513
     (and into the command's input)."
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   514
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   515
    |pipe externalStream shuffledStream shufflerProcess|
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   516
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   517
    (aStream isNil or:[aStream isExternalStream]) ifTrue:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   518
        ^ aStream.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   519
    ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   520
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   521
    pipe := NonPositionableExternalStream makePipe.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   522
    externalStream := pipe at:1.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   523
    shuffledStream := pipe at:2.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   524
    lineWise ifFalse:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   525
        shuffledStream blocking:false.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   526
    ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   527
    aStream isBinary ifTrue:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   528
        shuffledStream binary.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   529
    ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   530
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   531
    "/ start a reader process, shuffling data from the given
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   532
    "/ inStream to the pipe (which is connected to the commands input)
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   533
    shufflerProcess := 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   534
        [
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   535
            [
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   536
                lineWise ifTrue:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   537
                    "shuffle until end-of-input"
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   538
                    [aStream atEnd] whileFalse:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   539
                        |data|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   540
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   541
                        data := aStream nextLine.
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   542
                        data notNil ifTrue:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   543
                            shuffledStream nextPutLine:data.
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   544
                            shuffledStream flush.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   545
                        ].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   546
                    ].
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   547
                ] ifFalse:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   548
                    aStream copyToEndInto:shuffledStream.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   549
                ].
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   550
            ] on:WriteError do:[:ex|
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   551
                "ignore"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   552
            ] ensure:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   553
                shuffledStream close.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   554
            ]
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   555
        ] newProcess
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   556
            name:'OSProcess input shuffler';
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   557
"/                beSystemProcess;
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   558
            resume.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   559
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   560
    shufflerProcesses add:shufflerProcess.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   561
    streamsToClose add:externalStream.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   562
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   563
    ^ externalStream
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   564
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   565
    "Modified: / 31-01-2017 / 16:50:39 / stefan"
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   566
    "Modified (comment): / 23-02-2017 / 10:51:34 / Maren"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   567
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   568
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   569
setupShufflerForOutput:aStream
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   570
    "if aStream is an internal Stream, set up a pipe for the command output.
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   571
     Start a process that shuffles the data fron the pipe into the internal stream."
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   572
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   573
    |pipe externalStream shuffledStream shufflerProcess|
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   574
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   575
    (aStream isNil or:[aStream isExternalStream]) ifTrue:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   576
        ^ aStream.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   577
    ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   578
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   579
    pipe := NonPositionableExternalStream makePipe.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   580
    externalStream := pipe at:2.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   581
    shuffledStream := pipe at:1.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   582
    aStream isBinary ifTrue:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   583
        shuffledStream binary.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   584
    ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   585
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   586
    shufflerProcess := 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   587
        [
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   588
            [
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   589
                "shuffle until the pipe closes"
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   590
                lineWise ifTrue:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   591
                    [shuffledStream atEnd] whileFalse:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   592
                        |data|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   593
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   594
                        data := shuffledStream nextLine.
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   595
                        data notNil ifTrue:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   596
                            aStream nextPutLine:data
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   597
                        ].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   598
                    ].
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   599
                ] ifFalse:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   600
                    shuffledStream copyToEndInto:aStream.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   601
                ].
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   602
            ] on:WriteError do:[:ex |
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   603
                "ignore" 
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   604
            ] ensure:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   605
                shuffledStream close.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   606
            ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   607
        ] newProcess
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   608
            priority:(Processor userSchedulingPriority "+ 1");
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   609
            name:'OSProcess output shuffler';
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   610
"/                beSystemProcess;
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   611
            resume.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   612
21223
bebca95ca864 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21209
diff changeset
   613
    shufflerProcesses add:shufflerProcess.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   614
    streamsToClose add:externalStream.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   615
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   616
    ^ externalStream
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   617
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   618
    "Modified: / 31-01-2017 / 16:57:25 / stefan"
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   619
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   620
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   621
startCommand
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   622
    "the 'real' command to be executed.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   623
     Redefined for remote processes (eg. to construct a remote command string)"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   624
    
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   625
    ^ command
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   626
! !
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   627
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   628
!OSProcess methodsFor:'queries'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   629
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   630
finishedWithSuccess
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   631
    ^ exitStatus notNil and:[exitStatus success].
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   632
!
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   633
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   634
isAlive
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   635
    "answer true if the process is still alive"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   636
21205
580c1baf6e3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21200
diff changeset
   637
    ^ pid notNil and:[exitStatus isNil]
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   638
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   639
    "Modified (comment): / 23-02-2017 / 10:52:37 / Maren"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   640
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   641
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   642
isDead
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   643
    "answer true if the process is no longer alive"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   644
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   645
    ^ self isAlive not
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   646
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   647
    "Modified (comment): / 23-02-2017 / 10:52:31 / Maren"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   648
! !
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   649
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   650
!OSProcess methodsFor:'starting'!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   651
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   652
execute
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   653
    "execute the command. 
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   654
     Wait until it is finished.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   655
     Abort the execution if I am interrupted.
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   656
     Answer true if it terminated successfully, 
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   657
     false if it could not be started or terminated with error."
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   658
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   659
    |ok|
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   660
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   661
    [
21185
b2ecc061106c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21184
diff changeset
   662
        ok := self startProcess.
b2ecc061106c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21184
diff changeset
   663
        ok ifTrue:[
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   664
            self waitUntilFinished.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   665
            ok := self finishedWithSuccess.
21185
b2ecc061106c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21184
diff changeset
   666
        ].
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   667
    ] ifCurtailed:[
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   668
        "/ we were interrupted -
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   669
        "/ terminate the os-command (and all of its forked commands)
21185
b2ecc061106c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21184
diff changeset
   670
        pid notNil ifTrue:[
b2ecc061106c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21184
diff changeset
   671
            self terminateGroup.
b2ecc061106c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21184
diff changeset
   672
        ].
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   673
    ].
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   674
    ^ ok.
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   675
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   676
    "Modified (comment): / 23-02-2017 / 10:54:34 / Maren"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   677
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   678
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   679
startProcess
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   680
    "If there are non-external streams, setup transfer (shuffler) processes
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   681
     to transfer data from a pipe to the internal stream.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   682
     Start the command.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   683
     Answer true if the command could be started, false if not.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   684
     Return immediately (do not wait until the command is finished)." 
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   685
21200
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   686
    |externalInStream externalAuxStream externalErrorStream externalOutStream|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   687
21200
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   688
    shufflerProcesses := OrderedCollection new:4.
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   689
    streamsToClose := OrderedCollection new:2.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   690
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   691
    externalInStream := self setupShufflerForInput:inStream.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   692
    externalAuxStream := self setupShufflerForInput:auxStream.
21226
568b192939c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21223
diff changeset
   693
    externalOutStream := self setupShufflerForOutput:outStream.
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   694
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   695
    errorStream == outStream ifTrue:[
21226
568b192939c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21223
diff changeset
   696
        externalErrorStream := externalOutStream.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   697
    ] ifFalse:[
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   698
        externalErrorStream := self setupShufflerForOutput:errorStream.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   699
    ].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   700
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   701
    "start the command"
21200
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   702
    finishSema := EventSemaphore new.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   703
22983
954925788d5d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22568
diff changeset
   704
    "/ UserPreferences current logExecutedOSCommands:true
954925788d5d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22568
diff changeset
   705
    UserPreferences current logExecutedOSCommands ifTrue:[
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   706
        Transcript showCR:('OS command: ',self startCommand printString).  
22983
954925788d5d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22568
diff changeset
   707
    ].
954925788d5d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22568
diff changeset
   708
    
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   709
    Processor 
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   710
        monitor:[
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   711
            pid := OperatingSystem
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   712
                        startProcess:(self startCommand)
21200
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   713
                        inputFrom:externalInStream
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   714
                        outputTo:externalOutStream
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   715
                        errorTo:externalErrorStream
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   716
                        auxFrom:externalAuxStream
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   717
                        environment:environment
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   718
                        inDirectory:directory
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   719
                        newPgrp:newPgrp
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
   720
                        showWindow:showWindow.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   721
        ] 
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   722
        action:[:status |
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   723
            status stillAlive ifFalse:[
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   724
                exitStatus := status.
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   725
                pid notNil ifTrue:[
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   726
                    OperatingSystem closePid:pid.
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   727
                ].
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   728
                "/ shufflerProcesses do:[:eachProcess|
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   729
                "/     "terminate the shuffler processes.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   730
                "/      They close the local side of the pipe when being terminated"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   731
                "/    eachProcess terminate.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   732
                "/ ].
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   733
                
21223
bebca95ca864 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21209
diff changeset
   734
                finishSema signal.
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   735
                terminateActionBlock notNil ifTrue:[
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   736
                    terminateActionBlock valueWithOptionalArgument:status and:self.
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   737
                ].
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   738
            ].
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   739
        ].
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   740
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   741
    "we can close the remote side of the pipes after the os process has been started (after the fork)"
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   742
    streamsToClose do:[:eachStream | eachStream close].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   743
    streamsToClose := nil.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   744
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   745
    pid isNil ifTrue:[
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   746
        "process could not be started - terminate shufflers"
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   747
        shufflerProcesses do:[:eachProcess|
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   748
            eachProcess terminate.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   749
        ].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   750
        shufflerProcesses := nil.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   751
        exitStatus := OperatingSystem osProcessStatusClass processCreationFailure.
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   752
        finishSema signal.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   753
        ^ false.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   754
    ].
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   755
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   756
    ^ true.
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   757
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   758
    "Modified: / 22-05-2018 / 12:23:48 / Claus Gittinger"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   759
! !
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   760
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   761
!OSProcess methodsFor:'terminating'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   762
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   763
kill
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   764
    "kill the process - the process does not get the chance to clean up"
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   765
    
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   766
    pid notNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   767
        OperatingSystem killProcess:pid.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   768
    ].
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   769
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   770
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   771
killGroup
20379
135c4fc19014 #OTHER by mawalch
mawalch
parents: 19298
diff changeset
   772
    "kill the processGroup - the processes do not get the chance to clean up"
135c4fc19014 #OTHER by mawalch
mawalch
parents: 19298
diff changeset
   773
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   774
    pid notNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   775
        OperatingSystem 
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   776
            killProcessGroup:pid;
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   777
            killProcess:pid.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   778
    ].
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   779
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   780
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   781
terminate
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   782
    "terminate the process gracefully"
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   783
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   784
    pid notNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   785
        OperatingSystem terminateProcess:pid.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   786
    ].
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   787
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   788
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   789
terminateGroup
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   790
    "terminate the process group.
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   791
     Under Windows, this is the same as terminateWithAllChildren,
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   792
     under unix, this terminates a subset of all children"
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   793
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   794
    pid notNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   795
        OperatingSystem 
21632
747d14b5ff37 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21552
diff changeset
   796
            terminateProcess:pid;
747d14b5ff37 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21552
diff changeset
   797
            terminateProcessGroup:pid.
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   798
    ].
21551
a00b3ea45664 #DOCUMENTATION by Maren
matilk
parents: 21512
diff changeset
   799
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   800
    "Modified (comment): / 23-02-2017 / 10:50:13 / Maren"
21632
747d14b5ff37 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21552
diff changeset
   801
    "Modified: / 09-03-2017 / 15:00:58 / stefan"
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   802
! !
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   803
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   804
!OSProcess methodsFor:'waiting'!
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   805
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   806
waitUntilFinished
22148
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   807
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   808
    "wait with a veryy long timeout, 
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   809
     in order that ProcessorScheduler>>#checkForEndOfDispatch recogizes
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   810
     this waiting process as user process which is still alive.
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   811
     The timout is meant to never occur!!"
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   812
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   813
    ^ self waitUntilFinishedWithTimeout:60*60*24000
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   814
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   815
    "Modified: / 01-08-2017 / 14:41:10 / stefan"
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
   816
    "Modified (comment): / 01-08-2017 / 17:15:55 / stefan"
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   817
!
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   818
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   819
waitUntilFinishedWithTimeout:timeout
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   820
    |processList|
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   821
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   822
    (finishSema waitWithTimeout:timeout) isNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   823
        "timed out"
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   824
        ^ nil.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   825
    ].
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   826
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   827
    "have to wait until the shufflers have finished their work"
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   828
    processList := shufflerProcesses.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   829
    processList notEmptyOrNil ifTrue:[
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   830
        processList do:[:eachProcess | 
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   831
            eachProcess waitUntilTerminated.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   832
        ].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   833
        shufflerProcesses := nil.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   834
    ].
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   835
! !
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   836
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   837
!OSProcess::RemoteOSProcess class methodsFor:'documentation'!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   838
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   839
documentation
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   840
"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   841
    Instances of OSProcess represent operating system processes that can be executed.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   842
    (as opposed to Smalltalk processes).
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   843
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   844
    [author:]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   845
        cg
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   846
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   847
    [instance variables:]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   848
        host        String          the host on which to execute the command
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   849
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   850
    [class variables:]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   851
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   852
    [see also:]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   853
        Process
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   854
"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   855
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   856
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   857
examples
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   858
"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   859
                                                            [exBegin]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   860
    |outStream|
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   861
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   862
    outStream := '' writeStream.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   863
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   864
    (OSProcess onHost:'exeptn') 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   865
        command:'ls -l';
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   866
        inStream:'abc' readStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   867
        outStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   868
        lineWise:true;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   869
        execute.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   870
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   871
    outStream contents
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   872
                                                            [exEnd]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   873
"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   874
! !
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   875
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   876
!OSProcess::RemoteOSProcess methodsFor:'accessing'!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   877
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   878
host
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   879
    ^ host
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   880
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   881
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   882
host:aHostName
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   883
    host := aHostName.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   884
! !
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   885
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   886
!OSProcess::RemoteOSProcess methodsFor:'private'!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   887
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   888
startCommand
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   889
    "the 'real' command"
22199
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
   890
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
   891
    "for now, always use ssh; 
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
   892
     later, this should be configurable, 
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
   893
     which remote mechanism is to be used per host"
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
   894
     
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   895
    ^ 'ssh %1 "%2"' bindWith:host with:command
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   896
! !
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   897
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   898
!OSProcess class methodsFor:'documentation'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   899
19298
cfacc6b159c5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19286
diff changeset
   900
version
cfacc6b159c5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19286
diff changeset
   901
    ^ '$Header$'
cfacc6b159c5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19286
diff changeset
   902
!
cfacc6b159c5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19286
diff changeset
   903
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   904
version_CVS
19286
9e8eea97fd57 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   905
    ^ '$Header$'
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   906
! !
19286
9e8eea97fd57 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
   907
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   908
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   909
OSProcess initialize!