OSProcess.st
author Stefan Vogel <sv@exept.de>
Tue, 28 Apr 2020 16:21:34 +0200
changeset 25373 f030619565e1
parent 25323 72863286fa82
permissions -rw-r--r--
#REFACTORING by stefan class: ArrayedCollection class changed: #with:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24011
c7b1d5bd2166 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23907
diff changeset
     1
"{ Encoding: utf8 }"
c7b1d5bd2166 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23907
diff changeset
     2
25120
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
     3
"
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
     4
 COPYRIGHT (c) 2018 by eXept Software AG
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
     5
              All Rights Reserved
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
     6
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
     7
 This software is furnished under a license and may be used
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
     8
 only in accordance with the terms of that license and with the
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    10
 be provided or otherwise made available to, or used by, any
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    11
 other person.  No title to or ownership of the software is
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    12
 hereby transferred.
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    13
"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic' }"
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    15
19286
9e8eea97fd57 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
    16
"{ NameSpace: Smalltalk }"
9e8eea97fd57 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
    17
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    18
Object subclass:#OSProcess
23035
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
    19
	instanceVariableNames:'pid command environment directory inStream outStream errorStream
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
    20
		auxInStream auxOutStream showWindow lineWise newPgrp exitStatus
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
    21
		finishSema inputShufflerProcesses outputShufflerProcesses
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
    22
		streamsToClose terminateActionBlock'
23793
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
    23
	classVariableNames:'Instances'
23035
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
    24
	poolDictionaries:''
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
    25
	category:'System-Support'
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    26
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    27
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
    28
Object subclass:#ProcessListEntry
23204
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
    29
	instanceVariableNames:'executableName processID sessionName userName'
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
    30
	classVariableNames:''
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
    31
	poolDictionaries:''
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
    32
	privateIn:OSProcess
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
    33
!
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
    34
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    35
OSProcess subclass:#RemoteOSProcess
23035
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
    36
	instanceVariableNames:'host'
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
    37
	classVariableNames:'MethodPerHost'
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
    38
	poolDictionaries:''
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
    39
	privateIn:OSProcess
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    40
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
    41
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    42
!OSProcess class methodsFor:'documentation'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    43
25120
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    44
copyright
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    45
"
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    46
 COPYRIGHT (c) 2018 by eXept Software AG
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    47
              All Rights Reserved
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    48
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    49
 This software is furnished under a license and may be used
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    50
 only in accordance with the terms of that license and with the
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    51
 inclusion of the above copyright notice.   This software may not
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    52
 be provided or otherwise made available to, or used by, any
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    53
 other person.  No title to or ownership of the software is
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    54
 hereby transferred.
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    55
"
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    56
!
e88dea1b12b1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 25072
diff changeset
    57
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    58
documentation
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    59
"
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
    60
    Instances of OSProcess represent operating system processes that can be executed.
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    61
    (as opposed to Smalltalk processes).
24290
36a25191f3e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24018
diff changeset
    62
    Both local and remote processes are supported.
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    63
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    64
    commandString:
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    65
     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
    66
     - 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
    67
     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
    68
     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
    69
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    70
     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
    71
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    72
     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
    73
     and the other elements are the arguments to the command. 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    74
     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
    75
     by Smalltalk code (including piping through smalltalk streams & filters).
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    76
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    77
    [author:]
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    78
        Stefan Vogel (stefan@zwerg)
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    79
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    80
    [instance variables:]
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    81
        pid         SmallInteger    the process id
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
    82
        command     String          the command line of the running command.
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    83
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    84
    [class variables:]
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    85
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    86
    [see also:]
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    87
        Process
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    88
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    89
"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    90
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    91
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
    92
examples
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
    93
"
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    94
  send command's output to the Transcript:
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    95
                                                            [exBegin]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    96
    OSProcess new 
22986
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
    97
        terminateActionBlock:[:status | Transcript showCR:status. Transcript showCR:status isError];
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
    98
        command:'lsxxxx -l';
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
    99
        outStream:Transcript;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   100
        lineWise:true;
22986
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
   101
        startProcess.
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   102
                                                            [exEnd]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   103
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   104
  send command's output to my stdout (see console):
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   105
                                                            [exBegin]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   106
    OSProcess new 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   107
        command:'ls -l';
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   108
        outStream:Stdout;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   109
        execute.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   110
                                                            [exEnd]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   111
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   112
  send command's output to a Smalltalk stream:
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   113
                                                            [exBegin]
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   114
    |outStream|
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   115
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   116
    outStream := '' writeStream.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   117
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   118
    OSProcess new 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   119
        command:'ls -l';
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   120
        outStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   121
        execute.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   122
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   123
    outStream contents inspect.
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   124
                                                            [exEnd]
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   125
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   126
  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
   127
                                                            [exBegin]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   128
    |inStream outStream|
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   129
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   130
    inStream := 'hello world' readStream.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   131
    outStream := '' writeStream.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   132
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   133
    OSProcess new 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   134
        command:'tr ''a-z'' ''A-Z''';
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   135
        inStream:inStream;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   136
        outStream:outStream;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   137
        execute.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   138
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   139
    outStream contents inspect.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   140
                                                            [exEnd]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   141
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   142
  again, send output to a Smalltalk stream;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   143
  watch the stream getting filled after 10 seconds:
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   144
                                                            [exBegin]
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   145
    |outStream|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   146
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   147
    outStream := '' writeStream.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   148
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   149
    OSProcess new 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   150
        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
   151
        outStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   152
        errorStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   153
        startProcess.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   154
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   155
    outStream inspect
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   156
                                                            [exEnd]
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   157
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   158
  separate stdout and stderr:
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   159
                                                            [exBegin]
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   160
    |outStream errStream|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   161
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   162
    outStream := '' writeStream.
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   163
    errStream := '' writeStream.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   164
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   165
    OSProcess new 
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   166
        command:'ls -l && ls >&2';
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   167
        outStream:outStream;
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   168
        errorStream:errStream;
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   169
        startProcess.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   170
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   171
    outStream inspect.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   172
    errStream inspect.
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   173
                                                            [exEnd]
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   174
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   175
  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
   176
                                                            [exBegin]
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   177
    |outStream|
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   178
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   179
    outStream := '' writeStream.
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   180
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   181
    OSProcess new 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   182
        command:'';
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   183
        inStream:'ls -l' readStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   184
        outStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   185
        lineWise:true;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   186
        execute.
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   187
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   188
    outStream contents inspect
22197
444d71c29720 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22181
diff changeset
   189
                                                            [exEnd]
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   190
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   191
  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
   192
                                                            [exBegin]
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   193
    |outStream|
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   194
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   195
    outStream := '' writeStream.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   196
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   197
    (OSProcess onHost:'exeptn') 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   198
        command:'ls -l';
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   199
        outStream:outStream;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   200
        lineWise:true;
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   201
        execute.
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   202
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   203
    outStream contents inspect
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   204
                                                            [exEnd]
21512
a78759923d34 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21332
diff changeset
   205
"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   206
! !
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   207
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   208
!OSProcess class methodsFor:'instance creation'!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   209
23793
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   210
allInstancesDo:aBlock
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   211
    "return an initialized instance for a local process.
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   212
     Keep track of the new instance (so we can quickly enumerate all of them)"
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   213
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   214
    Instances notNil ifTrue:[ 
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   215
        Instances do:aBlock
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   216
    ].
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   217
    
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   218
    "
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   219
     super allInstances
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   220
     self allInstances
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   221
    "
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   222
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   223
    "Created: / 02-03-2019 / 19:19:41 / Claus Gittinger"
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   224
!
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   225
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   226
command:aCommandString
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   227
    "return an initialized instance to execute aCommandString
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   228
     in the current directory (for a local process)"
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   229
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   230
    ^ self new command:aCommandString.
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   231
!
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   232
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   233
command:aCommandString directory:aStringOrFilename
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   234
    "return an initialized instance to execute aCommandString 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   235
     in a given directory (for a local process)"
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   236
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   237
    ^ self new command:aCommandString directory:aStringOrFilename.
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   238
!
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   239
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   240
commandStringForProgramName:executableFile arguments:arrayOfStrings
23184
5527a9f0dfd4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23183
diff changeset
   241
    "generate a command line string from appending args (possibley quoted) to the exe-name (with spaces)"
5527a9f0dfd4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23183
diff changeset
   242
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   243
    ^ String streamContents:[:s |
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   244
        s nextPutAll:(self possiblyQuoted:executableFile asFilename pathName).
23182
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   245
        arrayOfStrings notNil ifTrue:[
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   246
            arrayOfStrings do:[:eachArg |
23183
76333ab19e6f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23182
diff changeset
   247
                s space.
23182
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   248
                s nextPutAll:(self possiblyQuoted:eachArg).
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   249
            ].
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   250
        ]
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   251
    ]
23182
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   252
23184
5527a9f0dfd4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23183
diff changeset
   253
    "Modified (comment): / 02-07-2018 / 20:50:29 / cg"
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   254
!
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   255
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   256
new
23793
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   257
    "return an initialized instance for a local process.
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   258
     Keep track of the new instance (so we can quickly enumerate all of them)"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   259
23793
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   260
    |newInst|
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   261
    
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   262
    Instances isNil ifTrue:[
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   263
        Instances := WeakIdentitySet new
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   264
    ].    
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   265
    newInst := self basicNew initialize.
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   266
    Instances add:newInst.
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   267
    ^ newInst
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   268
e4692ca78427 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23648
diff changeset
   269
    "Modified (comment): / 02-03-2019 / 19:15:25 / Claus Gittinger"
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   270
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   271
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   272
onHost:aHost
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   273
    "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
   274
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   275
    (SocketAddress hostName:aHost) isLocal ifTrue:[
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   276
        ^ self basicNew initialize.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   277
    ].
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   278
    ^ RemoteOSProcess basicNew host:aHost; initialize.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   279
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   280
    "
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   281
     OSProcess onHost:'localhost'
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   282
     OSProcess onHost:'exeptn'
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   283
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   284
     (OSProcess new) command:'ls'
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   285
     (OSProcess onHost:'exeptn') command:'ls'
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   286
    "
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   287
!
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   288
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   289
possiblyQuoted:aString
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   290
    "should we quote or escape?"
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   291
24018
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   292
    "/ better quote - qorks on Windows AND Unix
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   293
    ^ Filename possiblyQuotedPathname:aString.
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   294
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   295
"/    ^ String streamContents:[:s |
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   296
"/        aString do:[:ch |
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   297
"/            (ch isSeparator or:[ch = $\]) ifTrue:[
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   298
"/                s nextPut:$\
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   299
"/            ].
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   300
"/            s nextPut:ch
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   301
"/        ]
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   302
"/    ]
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   303
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   304
    "
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   305
     self possiblyQuoted:'foo bar' 
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   306
     self possiblyQuoted:'foo\bar'
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   307
    "
24018
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   308
8db2b5564d4b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24011
diff changeset
   309
    "Modified: / 28-03-2019 / 16:19:41 / Claus Gittinger"
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   310
!
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   311
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   312
programName:executableFile arguments:arrayOfStrings initialEnvironment:stringDictionary
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   313
    "similar to command:, but with separate command and arguments"
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   314
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   315
    ^ self new
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   316
        command:(self commandStringForProgramName:executableFile arguments:arrayOfStrings);
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   317
        environment:stringDictionary;
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   318
        yourself
23182
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   319
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   320
    "
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   321
     (self programName:'notepad.exe' arguments:#() initialEnvironment:nil)
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   322
        showWindow:true;
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   323
        startProcess
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   324
    "
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   325
6082d007b7c3 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23126
diff changeset
   326
    "Modified (comment): / 02-07-2018 / 20:33:02 / cg"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   327
! !
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   328
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   329
!OSProcess class methodsFor:'class initialization'!
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
initialize
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   332
    "Backward compatibility: Win32Process is an alias for OSProcess"
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   333
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   334
    Win32Process := self.
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   335
! !
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   336
22568
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   337
!OSProcess class methodsFor:'queries'!
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   338
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   339
defaultShellPath
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   340
    OperatingSystem isUNIXlike ifTrue:[
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   341
        ^ OperatingSystem getEnvironment:'SHELL' 
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   342
    ].
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   343
    ^ 'cmd'
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   344
! !
eb116af8c3a2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22439
diff changeset
   345
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   346
!OSProcess class methodsFor:'utilities'!
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   347
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   348
getTaskList
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   349
    "get a tasklist (Windows OS only)"
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   350
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   351
    |lines sepIdx entries|
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   352
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   353
    OperatingSystem isMSWINDOWSlike ifTrue:[
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   354
        lines := (PipeStream outputFromCommand:'tasklist') asStringCollection.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   355
        sepIdx := lines findFirst:[:line | line startsWith:'=='].
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   356
        sepIdx == 0 ifTrue:[ ^ #() ].
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   357
        entries := (lines from:(sepIdx + 1)) 
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   358
                        collect:[:line |
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   359
                            |s idx executableName processID userName|
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   360
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   361
                            s := line readStream.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   362
                            executableName := (s upToMatching:[:ch | ch isDigit]) withoutSeparators.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   363
                            processID := Integer readFrom:s.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   364
                            s skipSeparators.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   365
                            userName := s nextAlphaNumericWord.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   366
23204
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
   367
                            ProcessListEntry executableName:executableName processID:processID sessionName:userName
23202
d8eaf4da9e34 #REFACTORING by anharman
anharman
parents: 23201
diff changeset
   368
                        ]
d8eaf4da9e34 #REFACTORING by anharman
anharman
parents: 23201
diff changeset
   369
                        as:OrderedCollection.
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   370
    ] ifFalse:[
23213
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   371
        lines := (PipeStream outputFromCommand:'ps') asStringCollection.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   372
        sepIdx := lines findFirst:[:line | line withoutSeparators first isDigit].
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   373
        sepIdx == 0 ifTrue:[ ^ #() ].
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   374
        entries := (lines from:(sepIdx + 1)) 
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   375
                        collect:[:line |
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   376
                            |s idx executableName processID tty time|
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   377
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   378
                            s := line readStream.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   379
                            processID := Integer readFrom:s.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   380
                            s skipSeparators.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   381
                            tty := s upToSeparator.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   382
                            s skipSeparators.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   383
                            time := s upToSeparator.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   384
                            s skipSeparators.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   385
                            executableName := s upToEnd.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   386
                            (executableName startsWith:'-') ifTrue:[
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   387
                                executableName := executableName copyFrom:2.
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   388
                            ].    
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   389
                            ProcessListEntry executableName:executableName processID:processID sessionName:nil
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   390
                        ]
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   391
                        as:OrderedCollection.
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   392
    ].
23213
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   393
    ^ entries
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   394
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   395
    "
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   396
     self getTaskList
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   397
    "
23213
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   398
bd67ea22139d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23204
diff changeset
   399
    "Modified: / 16-07-2018 / 23:11:05 / Claus Gittinger"
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   400
! !
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
   401
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   402
!OSProcess methodsFor:'accessing'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   403
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   404
auxInStream
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   405
    ^ auxInStream
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   406
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   407
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   408
auxInStream:aStream
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   409
    "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
   410
     file descriptor 3"
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   411
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   412
    auxInStream := aStream.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   413
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   414
    "Modified (comment): / 23-02-2017 / 10:56:57 / Maren"
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   415
!
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   416
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   417
auxOutStream
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   418
    ^ auxOutStream
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   419
!
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   420
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   421
auxOutStream:aStream
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   422
    "set an auxiliary output stream that will be available to the command as
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   423
     file descriptor 4"
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   424
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   425
    auxOutStream := aStream.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   426
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   427
    "Modified (comment): / 23-02-2017 / 10:56:57 / Maren"
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   428
!
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   429
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   430
auxStream
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   431
    <resource: #obsolete>
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   432
    ^ self auxInStream
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   433
!
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   434
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   435
auxStream:aStream
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   436
    <resource: #obsolete>
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   437
    "set an auxiliary input stream that will be available to the command as
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   438
     file descriptor 3"
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   439
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   440
    self auxInStream:aStream.
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   441
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   442
    "Modified (comment): / 23-02-2017 / 10:56:57 / Maren"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   443
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   444
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   445
command
24682
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   446
    "the OS (shell-) command, as string or string-array"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   447
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   448
    ^ command
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   449
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   450
    "Created: / 10.11.1998 / 21:27:07 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   451
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   452
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   453
command:aStringOrArray 
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   454
    "set the command to be executed.
22439
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   455
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   456
     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
   457
     - 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
   458
     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
   459
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   460
     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
   461
     and the other elements are the arguments to the command. 
2a098663db2f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22438
diff changeset
   462
     No shell is invoked in this case."
22437
2eab35976e5e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22436
diff changeset
   463
    
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   464
    command := aStringOrArray.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   465
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   466
22436
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   467
command:commandStringArg directory:stringOrFilenameArg
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   468
    "set the command to be executed and directory, where to execute.
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   469
     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
   470
     - 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
   471
     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
   472
     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
   473
22436
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   474
    command := commandStringArg.
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   475
    directory := stringOrFilenameArg.
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   476
!
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   477
24822
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   478
command:commandArg directory:directoryArg outStream:outStreamArg errorStream:errorStreamArg 
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   479
    "set the command to be executed & directory, where to execute.
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   480
     and output/error streams.
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   481
     See comments in individual setters for more info"
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   482
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   483
    command := commandArg.
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   484
    directory := directoryArg.
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   485
    outStream := outStreamArg.
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   486
    errorStream := errorStreamArg.
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   487
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   488
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   489
!
24ceeb53827e #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24821
diff changeset
   490
23505
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   491
command:commandArg environment:environmentArg directory:directoryArg inStream:inStreamArg outStream:outStreamArg errorStream:errorStreamArg 
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   492
    "set the command to be executed & directory, where to execute.
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   493
     and input/output streams.
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   494
     See comments in individual setters for more info"
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   495
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   496
    command := commandArg.
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   497
    environment := environmentArg.
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   498
    directory := directoryArg.
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   499
    inStream := inStreamArg.
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   500
    outStream := outStreamArg.
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   501
    errorStream := errorStreamArg.
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   502
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   503
    "Created: / 04-11-2018 / 18:28:24 / Claus Gittinger"
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   504
!
54b7a8af8117 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23501
diff changeset
   505
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   506
command:commandArg environment:environmentArg directory:directoryArg inStream:inStreamArg outStream:outStreamArg errorStream:errorStreamArg auxInStream:auxInStreamArg auxOutStream:auxOutStreamArg showWindow:showWindowArg lineWise:lineWiseArg 
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   507
    "set the command to be executed & directory, where to execute.
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   508
     and input/output streams.
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   509
     See comments in individual setters for more info"
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   510
22181
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   511
    command := commandArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   512
    environment := environmentArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   513
    directory := directoryArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   514
    inStream := inStreamArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   515
    outStream := outStreamArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   516
    errorStream := errorStreamArg.
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   517
    auxInStream := auxInStreamArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   518
    auxOutStream := auxOutStreamArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   519
    showWindow := showWindowArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   520
    lineWise := lineWiseArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   521
!
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   522
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   523
command:commandArg environment:environmentArg directory:directoryArg inStream:inStreamArg outStream:outStreamArg errorStream:errorStreamArg auxStream:auxInStreamArg showWindow:showWindowArg lineWise:lineWiseArg 
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   524
    "set the command to be executed & directory, where to execute.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   525
     and input/output streams.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   526
     See comments in individual setters for more info"
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   527
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   528
    command := commandArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   529
    environment := environmentArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   530
    directory := directoryArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   531
    inStream := inStreamArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   532
    outStream := outStreamArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   533
    errorStream := errorStreamArg.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   534
    auxInStream := auxInStreamArg.
22181
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   535
    showWindow := showWindowArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   536
    lineWise := lineWiseArg.
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   537
!
fa3f71f80d13 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22148
diff changeset
   538
24820
301c642f32e7 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24724
diff changeset
   539
command:commandArg outStream:outStreamArg errorStream:errorStreamArg 
24821
a45e3af1bbcb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24820
diff changeset
   540
    "set the command to be executed and output+error streams.
24820
301c642f32e7 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24724
diff changeset
   541
     See comments in individual setters for more info"
301c642f32e7 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24724
diff changeset
   542
301c642f32e7 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24724
diff changeset
   543
    command := commandArg.
301c642f32e7 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24724
diff changeset
   544
    outStream := outStreamArg.
301c642f32e7 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24724
diff changeset
   545
    errorStream := errorStreamArg.
301c642f32e7 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24724
diff changeset
   546
!
301c642f32e7 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24724
diff changeset
   547
24682
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   548
commandString
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   549
    "the OS (shell-) command, as string"
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   550
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   551
    command isString ifTrue:[^ command].
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   552
    ^ command asStringWith:' '
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   553
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   554
    "Created: / 10.11.1998 / 21:27:07 / cg"
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   555
!
b56fdbd5003f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24681
diff changeset
   556
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   557
directory
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   558
    "the directory where executed"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   559
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   560
    ^ directory
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   561
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   562
    "Created: / 10.11.1998 / 21:21:52 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   563
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   564
22436
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   565
directory:aStringOrFilename
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   566
    "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
   567
22436
be3edafe55cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22199
diff changeset
   568
    directory := aStringOrFilename.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   569
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   570
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   571
environment
22438
7f0d16f4a407 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22437
diff changeset
   572
    "the shell environment"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   573
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   574
    ^ environment
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   575
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   576
    "Created: / 10.11.1998 / 21:26:34 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   577
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   578
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   579
environment:aDictionary
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   580
    "set the environment variables of the command to be executed"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   581
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   582
    environment := aDictionary.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   583
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   584
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   585
errorStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   586
    ^ errorStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   587
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   588
    "Created: / 10.11.1998 / 21:26:34 / cg"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   589
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   590
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   591
errorStream:aStream
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   592
    "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
   593
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   594
    errorStream := aStream.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   595
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   596
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   597
exitStatus
24681
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   598
    "answer the exit status of the command (instance of OSProcessStatus).
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   599
     or nil if the command has not yet been finished."
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   600
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   601
    ^ exitStatus
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   602
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   603
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   604
finishSema
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   605
    "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
   606
     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
   607
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   608
    ^ finishSema
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   609
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   610
    "Modified (comment): / 23-02-2017 / 10:53:17 / Maren"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   611
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   612
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   613
inStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   614
    ^ inStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   615
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   616
    "Created: / 10.11.1998 / 21:26:34 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   617
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   618
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   619
inStream:aStream
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   620
    "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
   621
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   622
    inStream := aStream.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   623
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   624
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   625
lineWise
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   626
    ^ lineWise
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   627
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   628
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   629
lineWise:aBoolean
21209
e9395c842124 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21208
diff changeset
   630
    "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
   631
     This is a bit slower than lineWise = false.
21208
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
     You may use it also when streaming to e.g. Transcript"
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   634
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   635
    lineWise := aBoolean.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   636
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   637
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   638
newPgrp
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   639
    ^ newPgrp
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   640
!
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   641
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   642
newPgrp:aBoolean
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   643
    "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
   644
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   645
    newPgrp := aBoolean.
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   646
!
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   647
23223
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   648
numericPid
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   649
    "answer the pid of the process the command is running in,
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   650
     or nil if the command has not yet been started.
23537
97943007572e #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23505
diff changeset
   651
     Always return an integer, even in windows where pid is a handle-"
23223
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   652
23635
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   653
    pid isOsHandle ifTrue:[
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   654
        ^ pid pid.
23223
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   655
    ].
23635
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   656
    ^ pid.  "Integer or nil"
23223
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   657
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   658
    "Created: / 19-07-2018 / 16:21:25 / Stefan Vogel"
23537
97943007572e #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23505
diff changeset
   659
    "Modified (comment): / 20-11-2018 / 16:50:26 / Stefan Vogel"
23223
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   660
!
ef9068ed4eae #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23213
diff changeset
   661
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   662
outStream
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   663
    "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
   664
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   665
    ^ outStream
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   666
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   667
    "Created: / 10.11.1998 / 21:26:34 / cg"
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   668
!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   669
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   670
outStream:aStream
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   671
    "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
   672
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   673
    outStream := aStream.
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   674
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   675
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   676
pid
23204
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
   677
    "answer the pid of the process the command is running in,
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
   678
     or nil if the command has not yet been started.
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
   679
     Notice: on Unix, the pid is an integer;
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
   680
     on Windows, it is a handle."
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   681
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   682
    ^ pid
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   683
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   684
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   685
showWindow
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   686
    ^ showWindow
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   687
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   688
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   689
showWindow:aBooleanOrNil
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   690
    "This parameter is ignored on Unix systems.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   691
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   692
     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
   693
     This is the OS's H_SHOWWINDOW argument.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   694
     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
   695
     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
   696
     executables will not.
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   697
     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
   698
     (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
   699
     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
   700
     In this case, pass an explicit false argument to suppress it."
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   701
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   702
    showWindow := aBooleanOrNil.
21206
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   703
!
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   704
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   705
terminateActionBlock
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   706
    "the (user provided) callback block,
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   707
     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
   708
     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
   709
21206
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   710
    ^ terminateActionBlock
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   711
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   712
    "Modified (comment): / 22-05-2018 / 12:21:24 / Claus Gittinger"
21206
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   713
!
aad552f2f306 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21205
diff changeset
   714
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   715
terminateActionBlock:aBlock
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   716
    "set the callback block,
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   717
     that will be called when the command has finished or was terminated.
22986
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
   718
     If non-nil, it will be called with optional argument:status and:self, the OSProcess.
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
   719
     WARNING: 
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
   720
        if the active-process calling #startProcess is already dead (i.e. terminated),
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
   721
        this callback will be called by the scheduler;
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
   722
        otherwise, the calling process will be interrupted to perform this callback.
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
   723
        Therefore: do not open any GUI or other blocking actions in it."
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   724
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   725
    terminateActionBlock := aBlock.
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
   726
22986
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
   727
    "Modified (comment): / 22-05-2018 / 12:42:21 / Claus Gittinger"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   728
! !
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   729
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   730
!OSProcess methodsFor:'initialization'!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   731
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   732
initialize
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   733
    "Invoked when a new instance is created."
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   734
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   735
    showWindow := false.    "/ for backward compatibility
21183
fdeb19204fb2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21182
diff changeset
   736
    lineWise := false.
fdeb19204fb2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21182
diff changeset
   737
    newPgrp := true.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   738
! !
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   739
23002
191ea99d1a08 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 22994
diff changeset
   740
13313
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   741
!OSProcess methodsFor:'printing'!
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   742
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   743
printOn:aStream
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   744
    aStream 
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   745
        nextPutAll:self className;
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   746
        nextPut:$(.
23641
d550133ce5f5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23635
diff changeset
   747
    exitStatus notNil ifTrue:[
d550133ce5f5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23635
diff changeset
   748
        exitStatus printOn:aStream.
d550133ce5f5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23635
diff changeset
   749
    ] ifFalse:[    
d550133ce5f5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23635
diff changeset
   750
        pid printOn:aStream.
d550133ce5f5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23635
diff changeset
   751
    ].        
13313
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   752
    aStream space.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   753
    command printOn:aStream.
13313
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   754
    aStream nextPut:$)
23641
d550133ce5f5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23635
diff changeset
   755
d550133ce5f5 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23635
diff changeset
   756
    "Modified: / 23-01-2019 / 13:55:08 / Claus Gittinger"
13313
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   757
! !
e5a29a7594be added: #printOn:
Stefan Vogel <sv@exept.de>
parents: 12890
diff changeset
   758
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   759
!OSProcess methodsFor:'private'!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   760
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   761
closeHelperStreams
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   762
    "close the helper streams that have been opened for shuffler processes
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   763
    (remote side of pipe)"
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   764
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   765
    |streams|
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   766
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   767
    streams := streamsToClose.
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   768
    streams notNil ifTrue:[
24496
2b2e06ad2c6e #UI_ENHANCEMENT by exept
Claus Gittinger <cg@exept.de>
parents: 24495
diff changeset
   769
        Logger debug:'OSProcess: closing leftover pipe streams for "%1"' with:self.
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   770
        streamsToClose := nil.
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   771
        streams do:[:eachStream | eachStream close].
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   772
    ].
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   773
!
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   774
24681
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   775
exitStatus:something
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   776
    "not used and should not be"
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   777
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   778
    exitStatus := something.
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   779
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   780
    "Created: / 10.11.1998 / 21:24:55 / cg"
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   781
!
8c57b9148dc9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24547
diff changeset
   782
23635
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   783
releasePid
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   784
    "only used in Windows, where pid is a handle that must be released"
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   785
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   786
    |pidHandle|
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   787
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   788
    pidHandle := pid.
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   789
    pidHandle isOsHandle ifFalse:[
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   790
        ^ self.
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   791
    ].
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   792
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   793
    pid := pidHandle pid.   "remember the numeric value"
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   794
    pidHandle close.
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   795
!
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
   796
25323
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   797
setupShufflerForInput:aReadStream
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   798
    "if aReadStream is an internal Stream, set up a pipe for the command input.
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   799
     Start a process that shuffles the data from the internal stream into the pipe
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   800
     (and into the command's input).
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   801
     Return the ExternalStream that should be passed to the OS process."
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   802
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   803
    |pipe externalStream shuffledStream shufflerProcess|
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   804
25323
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   805
    (aReadStream isNil or:[aReadStream isExternalStream]) ifTrue:[
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   806
        ^ aReadStream.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   807
    ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   808
23486
239a7ae42ee9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23482
diff changeset
   809
    pipe := PipeStream makePipe.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   810
    externalStream := pipe at:1.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   811
    shuffledStream := pipe at:2.
24011
c7b1d5bd2166 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23907
diff changeset
   812
    shuffledStream setCommandString:('Stdin of: ', command printString).
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   813
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   814
    "/ start a reader process, shuffling data from the given
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   815
    "/ 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
   816
    shufflerProcess := 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   817
        [
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   818
            [
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   819
                lineWise ifTrue:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   820
                    "shuffle until end-of-input"
25323
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   821
                    [aReadStream atEnd] whileFalse:[
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   822
                        |data|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   823
25323
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   824
                        data := aReadStream nextLine.
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   825
                        data notNil ifTrue:[
25323
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   826
                            shuffledStream nextPutLine:data; flush.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   827
                        ].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   828
                    ].
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   829
                ] ifFalse:[
25323
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   830
                    aReadStream isBinary ifTrue:[
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   831
                        shuffledStream binary.
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   832
                    ].
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   833
                    "#copyToEndInto: is non-blocking because is uses 
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   834
                     NonPositionableExternalStream >> #nextPutBytes:from:startingAt:"
72863286fa82 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 25302
diff changeset
   835
                    aReadStream copyToEndInto:shuffledStream.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   836
                ].
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   837
            ] on:WriteError do:[:ex|
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   838
                "ignore"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   839
            ] ensure:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   840
                shuffledStream close.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   841
            ]
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   842
        ] newProcess
23280
404e5d384583 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23223
diff changeset
   843
            name:'OSProcess: input shuffler';
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   844
"/                beSystemProcess;
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   845
            resume.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   846
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   847
    inputShufflerProcesses isNil ifTrue:[
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   848
        inputShufflerProcesses := OrderedCollection new:2.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   849
    ].
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   850
    inputShufflerProcesses add:shufflerProcess.
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   851
    streamsToClose isNil ifTrue:[
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   852
        streamsToClose := OrderedCollection new:4.
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   853
    ].
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   854
    streamsToClose add:externalStream.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   855
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   856
    ^ externalStream
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   857
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   858
    "Modified: / 31-01-2017 / 16:50:39 / stefan"
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   859
    "Modified (comment): / 23-02-2017 / 10:51:34 / Maren"
23486
239a7ae42ee9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23482
diff changeset
   860
    "Modified: / 29-10-2018 / 15:35:01 / Claus Gittinger"
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   861
    "Modified: / 01-11-2018 / 14:40:12 / Stefan Vogel"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   862
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   863
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   864
setupShufflerForOutput:aStream
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   865
    "if aStream is an internal Stream, set up a pipe for the command output.
23486
239a7ae42ee9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23482
diff changeset
   866
     Start a process that shuffles the data from the pipe's output
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   867
     into the internal stream.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   868
     Return the ExternalStream that should be passed to the OS process."
21182
001704ae8bbf #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21181
diff changeset
   869
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   870
    |pipe externalStream shuffledStream shufflerProcess|
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   871
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   872
    (aStream isNil or:[aStream isExternalStream]) ifTrue:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   873
        ^ aStream.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   874
    ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   875
23486
239a7ae42ee9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23482
diff changeset
   876
    pipe := PipeStream makePipe.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   877
    externalStream := pipe at:2.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   878
    shuffledStream := pipe at:1.
24011
c7b1d5bd2166 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23907
diff changeset
   879
    shuffledStream setCommandString:('Stdout/err of: ', command printString).
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   880
    aStream isBinary ifTrue:[
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   881
        shuffledStream binary.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   882
    ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   883
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   884
    shufflerProcess := 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   885
        [
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   886
            [
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   887
                "shuffle until the pipe closes"
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   888
                lineWise ifTrue:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   889
                    [shuffledStream atEnd] whileFalse:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   890
                        |data|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   891
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   892
                        data := shuffledStream nextLine.
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   893
                        data notNil ifTrue:[
24429
d9f5afe53e2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24290
diff changeset
   894
                            "/ Transcript showCR:'for: ',aStream printString.
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   895
                            aStream nextPutLine:data
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   896
                        ].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   897
                    ].
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   898
                ] ifFalse:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   899
                    shuffledStream copyToEndInto:aStream.
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
   900
                    aStream flush.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   901
                ].
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   902
            ] on:WriteError do:[:ex |
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   903
                "ignore" 
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   904
            ] ensure:[
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   905
                shuffledStream close.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   906
            ].
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   907
        ] newProcess
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   908
            priority:(Processor userSchedulingPriority "+ 1");
23280
404e5d384583 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23223
diff changeset
   909
            name:'OSProcess: output shuffler';
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   910
"/                beSystemProcess;
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   911
            resume.
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   912
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   913
    outputShufflerProcesses isNil ifTrue:[
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   914
        outputShufflerProcesses := OrderedCollection new:2.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   915
    ].
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   916
    outputShufflerProcesses add:shufflerProcess.
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   917
    streamsToClose isNil ifTrue:[
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   918
        streamsToClose := OrderedCollection new:4.
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
   919
    ].
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   920
    streamsToClose add:externalStream.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   921
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   922
    ^ externalStream
21332
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   923
18ca24f32565 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21226
diff changeset
   924
    "Modified: / 31-01-2017 / 16:57:25 / stefan"
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   925
    "Modified: / 01-11-2018 / 14:40:24 / Stefan Vogel"
24429
d9f5afe53e2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24290
diff changeset
   926
    "Modified: / 17-07-2019 / 19:53:26 / Claus Gittinger"
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   927
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   928
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   929
startCommand
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   930
    "the 'real' command to be executed.
22987
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
   931
     Redefined for remote processes (eg. to construct a remote command string).
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
   932
     Command may be both an Array or a String"
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   933
    
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
   934
    ^ command
22987
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
   935
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
   936
    "Modified (comment): / 22-05-2018 / 12:37:38 / Stefan Vogel"
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   937
!
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   938
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   939
terminateShufflerProcesses
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   940
    "terminate all the running shuffler processes"
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   941
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   942
    self 
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   943
        terminateShufflerProcesses:inputShufflerProcesses;
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   944
        terminateShufflerProcesses:outputShufflerProcesses.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   945
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   946
    inputShufflerProcesses := outputShufflerProcesses := nil.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   947
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   948
    "Created: / 01-11-2018 / 14:16:51 / Stefan Vogel"
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   949
    "Modified: / 01-11-2018 / 15:37:16 / Stefan Vogel"
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   950
!
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   951
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   952
terminateShufflerProcesses:aProcessCollection
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   953
    "terminate the running shuffler processes contained in aProcessCollection"
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   954
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   955
    |procs|
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   956
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   957
    procs := aProcessCollection.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   958
    procs notNil ifTrue:[
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
   959
        procs copy do:[:eachProc | eachProc terminate].
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   960
        procs removeAll.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   961
    ].
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   962
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   963
    "Created: / 01-11-2018 / 14:35:51 / Stefan Vogel"
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
   964
    "Modified: / 01-11-2018 / 15:36:12 / Stefan Vogel"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   965
! !
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   966
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   967
!OSProcess methodsFor:'queries'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   968
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   969
finishedWithSuccess
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
   970
    "return true if so"
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
   971
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   972
    ^ exitStatus notNil and:[exitStatus success].
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   973
!
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
   974
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   975
isAlive
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   976
    "answer true if the process is still alive"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   977
21205
580c1baf6e3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21200
diff changeset
   978
    ^ pid notNil and:[exitStatus isNil]
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   979
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   980
    "Modified (comment): / 23-02-2017 / 10:52:37 / Maren"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   981
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   982
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   983
isDead
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   984
    "answer true if the process is no longer alive"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   985
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   986
    ^ self isAlive not
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   987
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   988
    "Modified (comment): / 23-02-2017 / 10:52:31 / Maren"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   989
! !
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   990
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   991
!OSProcess methodsFor:'starting'!
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
   992
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
   993
execute
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   994
    "execute the command. 
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
   995
     Wait until it is finished.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   996
     Abort the execution if I am interrupted.
24547
3806eac205ea #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24496
diff changeset
   997
     Answer true if it successfully terminated, 
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
   998
     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
   999
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1000
    |ok|
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1001
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1002
    [
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1003
        ok := self startProcess.
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1004
        self waitUntilFinished.
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1005
        ok := ok & self finishedWithSuccess.
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1006
        self waitForShufflersToFinish
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1007
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1008
        "if we come here, all streamsToClose have been closed 
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1009
         and all shuffler processses are terminated"
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1010
    ] ifCurtailed:[
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1011
        "we have been interrupted -
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1012
         terminate the os-command (and all of its forked commands), and clean up"
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1013
        pid notNil ifTrue:[
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1014
            self terminateGroup.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1015
        ].
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1016
        self waitUntilFinished.
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1017
        self 
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1018
            closeHelperStreams; 
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1019
            terminateShufflerProcesses.
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
  1020
    ].
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1021
    ^ ok
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1022
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1023
    "Modified: / 29-10-2018 / 15:59:33 / Claus Gittinger"
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1024
    "Modified: / 31-10-2018 / 12:31:42 / Maren"
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1025
    "Modified (format): / 01-11-2018 / 15:00:01 / Stefan Vogel"
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1026
!
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1027
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1028
executeKeepingProcess
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1029
    "execute the command. 
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1030
     If I am interrupted keep the process as background process. 
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1031
     Wait until it is finished.
24547
3806eac205ea #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24496
diff changeset
  1032
     Answer true if it successfully terminated, 
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1033
     false if it could not be started or terminated with error."
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1034
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1035
    ^ [
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1036
        self startProcess
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1037
        and:[
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1038
            self waitUntilFinished.
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1039
            self finishedWithSuccess.
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1040
        ].
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1041
        "if we come here, all streamsToClose have been closed 
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1042
         and all shuffler processses are terminated"
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1043
    ] ifCurtailed:[
24495
57144657996c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24471
diff changeset
  1044
        "we have been interrupted - clean up.
57144657996c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24471
diff changeset
  1045
         Different from #execute - here we do NOT terminate the OS-command"
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1046
        self 
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1047
            closeHelperStreams; 
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1048
            terminateShufflerProcesses;
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1049
            releasePid.
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1050
    ].
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
  1051
23486
239a7ae42ee9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23482
diff changeset
  1052
    "Modified: / 29-10-2018 / 15:59:33 / Claus Gittinger"
23493
1a37df0ecc81 #BUGFIX by Maren
matilk
parents: 23490
diff changeset
  1053
    "Modified: / 31-10-2018 / 12:31:42 / Maren"
24495
57144657996c #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24471
diff changeset
  1054
    "Modified (format): / 30-07-2019 / 12:00:12 / Stefan Vogel"
21181
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
  1055
!
a8a9220ed86f #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21172
diff changeset
  1056
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1057
startProcess
22987
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
  1058
    "Start the command asynchronously (i.e. don't wait until is has finished).
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
  1059
     If there are non-external streams, setup transfer (shuffler) processes
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1060
     to transfer data from a pipe to the internal stream.
22987
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
  1061
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
  1062
     Answer true if the command could started succesfully, false if not.
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
  1063
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
  1064
     NOTE: under normal circumstances, even if the command cannot be found,
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
  1065
           the exit fom the command interpreter/shell is done some time later
3ee91cc9e2d0 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22986
diff changeset
  1066
           So you have to check later or set #terminateActionBlock: and check there."
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1067
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1068
    |externalInStream externalAuxInStream externalErrorStream externalOutStream 
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1069
     externalAuxOutStream callingProcess|
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1070
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1071
    externalInStream := self setupShufflerForInput:inStream.
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1072
    auxInStream notNil ifTrue:[
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1073
        externalAuxInStream := self setupShufflerForInput:auxInStream.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1074
    ].
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1075
    auxOutStream notNil ifTrue:[
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1076
        externalAuxOutStream := self setupShufflerForOutput:auxOutStream.
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1077
    ].
21226
568b192939c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21223
diff changeset
  1078
    externalOutStream := self setupShufflerForOutput:outStream.
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1079
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1080
    errorStream == outStream ifTrue:[
21226
568b192939c7 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21223
diff changeset
  1081
        externalErrorStream := externalOutStream.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1082
    ] ifFalse:[
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1083
        externalErrorStream := self setupShufflerForOutput:errorStream.
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1084
    ].
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1085
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1086
    "start the command"
21200
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
  1087
    finishSema := EventSemaphore new.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1088
22983
954925788d5d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22568
diff changeset
  1089
    "/ UserPreferences current logExecutedOSCommands:true
954925788d5d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22568
diff changeset
  1090
    UserPreferences current logExecutedOSCommands ifTrue:[
23002
191ea99d1a08 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 22994
diff changeset
  1091
        Transcript showCR:(('OS command: ', self startCommand printString) withColor:Color brown).  
22983
954925788d5d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22568
diff changeset
  1092
    ].
22986
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
  1093
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
  1094
    callingProcess := Processor activeProcess.
22983
954925788d5d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22568
diff changeset
  1095
    
25070
26915eb67235 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24822
diff changeset
  1096
    pid := Processor 
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1097
        monitor:[
25070
26915eb67235 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24822
diff changeset
  1098
            OperatingSystem
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1099
                        startProcess:(self startCommand)
21200
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
  1100
                        inputFrom:externalInStream
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
  1101
                        outputTo:externalOutStream
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
  1102
                        errorTo:externalErrorStream
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1103
                        auxFrom:externalAuxInStream
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1104
                        aux2To:externalAuxOutStream
21200
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
  1105
                        environment:environment
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
  1106
                        inDirectory:directory
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
  1107
                        newPgrp:newPgrp
6de129aead00 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21185
diff changeset
  1108
                        showWindow:showWindow.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1109
        ] 
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1110
        action:[:status |
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1111
            status stillAlive ifFalse:[
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1112
                exitStatus := status.
24429
d9f5afe53e2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24290
diff changeset
  1113
                "/ cg: why this? Isn't the process already dead?
23006
0427d51adb60 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23002
diff changeset
  1114
                self terminate.
0427d51adb60 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23002
diff changeset
  1115
21223
bebca95ca864 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21209
diff changeset
  1116
                finishSema signal.
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
  1117
                terminateActionBlock notNil ifTrue:[
23391
739e979f034d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23280
diff changeset
  1118
                    callingProcess isDead ifTrue:[
739e979f034d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23280
diff changeset
  1119
                        Error catch:[
739e979f034d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23280
diff changeset
  1120
                            "don't bother ProcessorScheduler with errors from terminateActionBlock!!"
739e979f034d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23280
diff changeset
  1121
                            terminateActionBlock valueWithOptionalArgument:status and:self.
739e979f034d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23280
diff changeset
  1122
                        ].
22986
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
  1123
                    ] ifFalse:[
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
  1124
                        callingProcess 
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
  1125
                            interruptWith:[
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
  1126
                                terminateActionBlock valueWithOptionalArgument:status and:self.
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
  1127
                            ]        
6574facad5bf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22985
diff changeset
  1128
                    ].    
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
  1129
                ].
23635
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
  1130
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
  1131
                self releasePid.
b01b7b318310 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23537
diff changeset
  1132
23126
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1133
                UserPreferences current logExecutedOSCommands ifTrue:[
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1134
                    Transcript 
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1135
                        showCR:(('OS command finished: %1 status: %2'
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1136
                                    bindWith: self startCommand
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1137
                                    with:status code)     
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1138
                                    withColor:(
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1139
                                        status success 
23907
f0b35054f5d0 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23793
diff changeset
  1140
                                            ifTrue:[Color darkGreen]
23126
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1141
                                            ifFalse:[Color red])).  
afbeb2bb7afc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23035
diff changeset
  1142
                ].
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1143
            ].
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1144
        ].
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1145
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1146
    "we can close the remote side of the pipes after the os process has been started (after the fork)"
24471
289363dea03a #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 24429
diff changeset
  1147
    self closeHelperStreams.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1148
23488
d7b7d8f25368 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23486
diff changeset
  1149
    "/ nil those references here, because there is still a home-context reference from the
d7b7d8f25368 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23486
diff changeset
  1150
    "/ monitor-pid action block. Otheriwse, the garbage collector might not collect them.
24724
b1afe939b13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24687
diff changeset
  1151
    externalInStream := externalAuxInStream := externalAuxOutStream := externalOutStream := externalErrorStream := nil.
23488
d7b7d8f25368 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23486
diff changeset
  1152
    
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1153
    pid isNil ifTrue:[
25070
26915eb67235 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24822
diff changeset
  1154
        "process could not be started!!"
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1155
        self terminateShufflerProcesses.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1156
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1157
        exitStatus := OperatingSystem osProcessStatusClass processCreationFailure.
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1158
        finishSema signal.
23006
0427d51adb60 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23002
diff changeset
  1159
        terminateActionBlock notNil ifTrue:[
0427d51adb60 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23002
diff changeset
  1160
            terminateActionBlock valueWithOptionalArgument:exitStatus and:self.
0427d51adb60 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23002
diff changeset
  1161
        ].
25070
26915eb67235 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24822
diff changeset
  1162
        UserPreferences current logExecutedOSCommands ifTrue:[
26915eb67235 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24822
diff changeset
  1163
            Transcript 
26915eb67235 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24822
diff changeset
  1164
                showCR:(('OS command failed: %1'bindWith: self startCommand) allRed).  
26915eb67235 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24822
diff changeset
  1165
        ].
26915eb67235 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24822
diff changeset
  1166
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1167
        ^ false.
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1168
    ].
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1169
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1170
    ^ true.
22985
da550df21477 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22984
diff changeset
  1171
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1172
    "Modified: / 01-11-2018 / 14:41:12 / Stefan Vogel"
23907
f0b35054f5d0 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23793
diff changeset
  1173
    "Modified: / 13-03-2019 / 21:13:05 / Claus Gittinger"
24429
d9f5afe53e2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24290
diff changeset
  1174
    "Modified (comment): / 17-07-2019 / 19:33:43 / Claus Gittinger"
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1175
! !
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1176
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1177
!OSProcess methodsFor:'terminating'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1178
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1179
kill
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1180
    "kill the process - the process does not get the chance to clean up"
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1181
    
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1182
    pid notNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1183
        OperatingSystem killProcess:pid.
25072
cd9ca7569011 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25070
diff changeset
  1184
        "do not release the pid here. The release is done,
cd9ca7569011 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25070
diff changeset
  1185
         after the process reported its termination!!"
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1186
    ].
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1187
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1188
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1189
killGroup
20379
135c4fc19014 #OTHER by mawalch
mawalch
parents: 19298
diff changeset
  1190
    "kill the processGroup - the processes do not get the chance to clean up"
135c4fc19014 #OTHER by mawalch
mawalch
parents: 19298
diff changeset
  1191
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1192
    pid notNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1193
        OperatingSystem 
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1194
            killProcessGroup:pid;
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1195
            killProcess:pid.
25072
cd9ca7569011 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25070
diff changeset
  1196
        "do not release the pid here. The release is done,
cd9ca7569011 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25070
diff changeset
  1197
         after the process reported its termination!!"
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1198
    ].
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1199
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1200
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1201
terminate
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1202
    "terminate the process gracefully"
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1203
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1204
    pid notNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1205
        OperatingSystem terminateProcess:pid.
25072
cd9ca7569011 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25070
diff changeset
  1206
        "do not release the pid here. The release is done,
cd9ca7569011 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25070
diff changeset
  1207
         after the process reported its termination!!"
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1208
    ].
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1209
!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1210
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1211
terminateGroup
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1212
    "terminate the process group.
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
  1213
     Under Windows, this is the same as terminateWithAllChildren,
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1214
     under unix, this terminates a subset of all children"
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1215
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1216
    pid notNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1217
        OperatingSystem 
21632
747d14b5ff37 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21552
diff changeset
  1218
            terminateProcess:pid;
747d14b5ff37 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21552
diff changeset
  1219
            terminateProcessGroup:pid.
25072
cd9ca7569011 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25070
diff changeset
  1220
        "do not release the pid here. The release is done,
cd9ca7569011 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 25070
diff changeset
  1221
         after the process reported its termination!!"
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1222
    ].
21551
a00b3ea45664 #DOCUMENTATION by Maren
matilk
parents: 21512
diff changeset
  1223
21552
7732a5719d14 #DOCUMENTATION by Maren
matilk
parents: 21551
diff changeset
  1224
    "Modified (comment): / 23-02-2017 / 10:50:13 / Maren"
21632
747d14b5ff37 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21552
diff changeset
  1225
    "Modified: / 09-03-2017 / 15:00:58 / stefan"
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1226
! !
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1227
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1228
!OSProcess methodsFor:'waiting'!
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1229
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1230
waitForShufflersToFinish
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1231
    "return false if timedout; true if finished"
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1232
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1233
    |processList|
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1234
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1235
    "have to wait until the output shufflers shuffling command's outputs have finished their work"
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1236
    processList := outputShufflerProcesses.
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1237
    processList notNil ifTrue:[
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1238
        processList do:[:eachProcess | 
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1239
            eachProcess waitUntilTerminated.
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1240
        ].
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1241
        outputShufflerProcesses := nil.
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1242
    ].
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1243
!
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1244
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1245
waitUntilFinished
23035
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
  1246
    <resource: #skipInDebuggersWalkBack>
22148
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
  1247
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1248
    "wait with a veeeeeery long timeout, 
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1249
     in order that ProcessorScheduler>>#checkForEndOfDispatch recognizes
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1250
     this waiting process as an user process which is still alive.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1251
     The timeout is meant to never occur!!"
22148
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
  1252
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
  1253
    ^ self waitUntilFinishedWithTimeout:60*60*24000
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
  1254
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
  1255
    "Modified: / 01-08-2017 / 14:41:10 / stefan"
9f3d3f09551d #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21632
diff changeset
  1256
    "Modified (comment): / 01-08-2017 / 17:15:55 / stefan"
23035
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
  1257
    "Modified: / 30-05-2018 / 13:57:42 / Claus Gittinger"
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1258
    "Modified (comment): / 01-11-2018 / 14:43:46 / Stefan Vogel"
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1259
!
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1260
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1261
waitUntilFinishedWithTimeout:timeout
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1262
    "return false if timedout; true if finished"
23035
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
  1263
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1264
    <resource: #skipInDebuggersWalkBack>
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1265
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1266
    (finishSema waitWithTimeout:timeout) isNil ifTrue:[
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1267
        "timed out"
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1268
        ^ false.
21208
9fbb51649256 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21206
diff changeset
  1269
    ].
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1270
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1271
    "have to wait until the output shufflers shuffling command's outputs have finished their work"
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1272
    self waitForShufflersToFinish.
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1273
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1274
    "command has finished and is no longer reading from its inputs"
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1275
    inputShufflerProcesses notNil ifTrue:[
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1276
        self terminateShufflerProcesses:inputShufflerProcesses.
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1277
        inputShufflerProcesses := nil.
21184
190ae0ab71c2 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21183
diff changeset
  1278
    ].
25302
3ab39726c023 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 25120
diff changeset
  1279
    ^ true
23035
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
  1280
98ae4fba66a8 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 23006
diff changeset
  1281
    "Modified: / 30-05-2018 / 13:57:39 / Claus Gittinger"
23501
d362810d013c #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23493
diff changeset
  1282
    "Modified: / 01-11-2018 / 15:53:09 / Stefan Vogel"
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1283
! !
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1284
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1285
!OSProcess::ProcessListEntry class methodsFor:'documentation'!
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1286
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1287
documentation
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1288
"
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1289
    documentation to be added.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1290
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1291
    [author:]
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1292
        anharman
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1293
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1294
    [instance variables:]
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1295
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1296
    [class variables:]
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1297
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1298
    [see also:]
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1299
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1300
"
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1301
! !
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1302
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1303
!OSProcess::ProcessListEntry class methodsFor:'instance creation'!
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1304
23204
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1305
executableName:executableNameArg processID:processIDArg sessionName:sessionNameArg 
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1306
    ^ self new executableName:executableNameArg processID:processIDArg sessionName:sessionNameArg 
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1307
!
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1308
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1309
executableName:executableNameArg processID:processIDArg userName:userNameArg 
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1310
    ^ self new executableName:executableNameArg processID:processIDArg userName:userNameArg 
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1311
! !
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1312
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1313
!OSProcess::ProcessListEntry methodsFor:'accessing'!
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1314
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1315
executableName
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1316
    ^ executableName
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1317
!
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1318
23204
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1319
executableName:executableNameArg processID:processIDArg sessionName:sessionNameArg 
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1320
    executableName := executableNameArg.
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1321
    processID := processIDArg.
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1322
    sessionName := sessionNameArg.
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1323
!
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1324
23201
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1325
executableName:executableNameArg processID:processIDArg userName:userNameArg 
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1326
    executableName := executableNameArg.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1327
    processID := processIDArg.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1328
    userName := userNameArg.
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1329
!
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1330
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1331
processID
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1332
    ^ processID
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1333
!
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1334
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1335
userName
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1336
    ^ userName
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1337
! !
70c0a58e1ab5 #FEATURE by anharman
anharman
parents: 23184
diff changeset
  1338
23204
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1339
!OSProcess::ProcessListEntry methodsFor:'printing & storing'!
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1340
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1341
printOn:aStream
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1342
    aStream nextPutAll:('(process: %1 pid: %2)' bindWith:executableName with:processID)
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1343
! !
1e76e9ae7986 #DOCUMENTATION by anharman
anharman
parents: 23202
diff changeset
  1344
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1345
!OSProcess::RemoteOSProcess class methodsFor:'documentation'!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1346
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1347
documentation
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1348
"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1349
    Instances of OSProcess represent operating system processes that can be executed.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1350
    (as opposed to Smalltalk processes).
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1351
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1352
    [author:]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1353
        cg
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1354
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1355
    [instance variables:]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1356
        host        String          the host on which to execute the command
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1357
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1358
    [class variables:]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1359
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1360
    [see also:]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1361
        Process
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1362
"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1363
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1364
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1365
examples
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1366
"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1367
                                                            [exBegin]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1368
    |outStream|
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1369
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1370
    outStream := '' writeStream.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1371
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1372
    (OSProcess onHost:'exeptn') 
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1373
        command:'ls -l';
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1374
        inStream:'abc' readStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1375
        outStream:outStream;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1376
        lineWise:true;
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1377
        execute.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1378
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1379
    outStream contents
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1380
                                                            [exEnd]
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1381
"
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1382
! !
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1383
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1384
!OSProcess::RemoteOSProcess methodsFor:'accessing'!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1385
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1386
host
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1387
    ^ host
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1388
!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1389
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1390
host:aHostName
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1391
    host := aHostName.
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1392
! !
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1393
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1394
!OSProcess::RemoteOSProcess methodsFor:'private'!
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1395
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1396
startCommand
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1397
    "the 'real' command"
22199
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
  1398
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
  1399
    "for now, always use ssh; 
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
  1400
     later, this should be configurable, 
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
  1401
     which remote mechanism is to be used per host"
4638d345471d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22198
diff changeset
  1402
     
22198
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1403
    ^ 'ssh %1 "%2"' bindWith:host with:command
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1404
! !
c81fce52627d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22197
diff changeset
  1405
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1406
!OSProcess class methodsFor:'documentation'!
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1407
19298
cfacc6b159c5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19286
diff changeset
  1408
version
cfacc6b159c5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19286
diff changeset
  1409
    ^ '$Header$'
cfacc6b159c5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19286
diff changeset
  1410
!
cfacc6b159c5 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19286
diff changeset
  1411
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1412
version_CVS
19286
9e8eea97fd57 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
  1413
    ^ '$Header$'
12890
2488b1f65af2 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
  1414
! !
19286
9e8eea97fd57 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 13313
diff changeset
  1415
21172
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1416
36a0e5430705 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20379
diff changeset
  1417
OSProcess initialize!