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