PipeStream.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 23878 a08a25c24390
child 25299 391acf8707e3
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:
23041
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
     1
"{ Encoding: utf8 }"
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 99
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5388
bef4d52749a4 terminate command on close (also under unix)
Claus Gittinger <cg@exept.de>
parents: 5243
diff changeset
    14
"{ Package: 'stx:libbasic' }"
bef4d52749a4 terminate command on close (also under unix)
Claus Gittinger <cg@exept.de>
parents: 5243
diff changeset
    15
17460
27b6fcc56477 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17077
diff changeset
    16
"{ NameSpace: Smalltalk }"
27b6fcc56477 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17077
diff changeset
    17
269
93162487a94b *** empty log message ***
claus
parents: 255
diff changeset
    18
NonPositionableExternalStream subclass:#PipeStream
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
    19
	instanceVariableNames:'commandString osProcess'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    20
	classVariableNames:'BrokenPipeSignal'
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    21
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    22
	category:'Streams-External'
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
!
2
claus
parents: 1
diff changeset
    24
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
    25
!PipeStream primitiveDefinitions!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
%{
17077
8f4500d0df9e include os defs
Claus Gittinger <cg@exept.de>
parents: 16953
diff changeset
    27
#include "stxOSDefs.h"
437
claus
parents: 410
diff changeset
    28
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 18785
diff changeset
    29
#if defined(__win32__)
793
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    30
# undef UNIX_LIKE
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    31
# define MSDOS_LIKE
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    32
#endif
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    33
20298
98dc8dbdd8cf include files
Claus Gittinger <cg@exept.de>
parents: 20099
diff changeset
    34
#ifndef _STDIO_H_INCLUDED_
98dc8dbdd8cf include files
Claus Gittinger <cg@exept.de>
parents: 20099
diff changeset
    35
# include <stdio.h>
98dc8dbdd8cf include files
Claus Gittinger <cg@exept.de>
parents: 20099
diff changeset
    36
# define _STDIO_H_INCLUDED_
98dc8dbdd8cf include files
Claus Gittinger <cg@exept.de>
parents: 20099
diff changeset
    37
#endif
437
claus
parents: 410
diff changeset
    38
20298
98dc8dbdd8cf include files
Claus Gittinger <cg@exept.de>
parents: 20099
diff changeset
    39
#ifndef _ERRNO_H_INCLUDED_
98dc8dbdd8cf include files
Claus Gittinger <cg@exept.de>
parents: 20099
diff changeset
    40
# include <errno.h>
98dc8dbdd8cf include files
Claus Gittinger <cg@exept.de>
parents: 20099
diff changeset
    41
# define _ERRNO_H_INCLUDED_
98dc8dbdd8cf include files
Claus Gittinger <cg@exept.de>
parents: 20099
diff changeset
    42
#endif
437
claus
parents: 410
diff changeset
    43
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    44
#ifndef transputer
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    45
# include <sys/types.h>
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    46
# include <sys/stat.h>
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    47
#endif
230
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    48
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    49
/*
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    50
 * on some systems errno is a macro ... check for it here
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    51
 */
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    52
#ifndef errno
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    53
 extern errno;
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    54
#endif
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    55
1663
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
    56
#ifdef LINUX
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
    57
# define BUGGY_STDIO_LIB
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
    58
#endif
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
    59
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    60
%}
180
c488255bd0be *** empty log message ***
claus
parents: 159
diff changeset
    61
! !
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    62
325
claus
parents: 308
diff changeset
    63
!PipeStream primitiveFunctions!
claus
parents: 308
diff changeset
    64
%{
claus
parents: 308
diff changeset
    65
claus
parents: 308
diff changeset
    66
/*
2925
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    67
 * no longer needed - popen is useless ...
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    68
 */
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    69
#undef NEED_POPEN_WITH_VFORK
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    70
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    71
/*
325
claus
parents: 308
diff changeset
    72
 * some systems (i.e. ultrix) use fork;
16953
4fb3033a379f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 16579
diff changeset
    73
 * we're better off with a popen based on vfork ...
325
claus
parents: 308
diff changeset
    74
 */
claus
parents: 308
diff changeset
    75
#ifdef NEED_POPEN_WITH_VFORK
claus
parents: 308
diff changeset
    76
claus
parents: 308
diff changeset
    77
static int popen_pid = 0;
claus
parents: 308
diff changeset
    78
claus
parents: 308
diff changeset
    79
FILE *
claus
parents: 308
diff changeset
    80
popen(command, type)
claus
parents: 308
diff changeset
    81
/* const */ char *command;
claus
parents: 308
diff changeset
    82
/* const */ char *type;
claus
parents: 308
diff changeset
    83
{
claus
parents: 308
diff changeset
    84
    int pipes[2];
claus
parents: 308
diff changeset
    85
    int itype = (strcmp(type, "w") == 0 ? 1 : 0);
claus
parents: 308
diff changeset
    86
claus
parents: 308
diff changeset
    87
    if (pipe(pipes) == -1)
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    88
	return NULL;
325
claus
parents: 308
diff changeset
    89
claus
parents: 308
diff changeset
    90
    switch (popen_pid = vfork()) {
claus
parents: 308
diff changeset
    91
    case -1:
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    92
	(void)close(pipes[0]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    93
	(void)close(pipes[1]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    94
	return NULL;
325
claus
parents: 308
diff changeset
    95
claus
parents: 308
diff changeset
    96
    case 0:
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    97
	if (itype) {
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    98
	    dup2(pipes[0], fileno(stdin));
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    99
	    close(pipes[1]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   100
	} else {
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   101
	    dup2(pipes[1], fileno(stdout));
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   102
	    close(pipes[0]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   103
	}
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   104
	execl("/bin/sh", "/bin/sh", "-c", command, 0);
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   105
	console_fprintf(stderr, "PipeStream [warning]: execlp failed in popen\n");
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   106
	_exit(-1);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   107
	/* NOTREACHED */
325
claus
parents: 308
diff changeset
   108
claus
parents: 308
diff changeset
   109
    default:
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   110
	    if (itype) {
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   111
		close(pipes[0]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   112
		return fdopen(pipes[1], "w");
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   113
	    } else {
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   114
		close(pipes[1]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   115
		return fdopen(pipes[0], "r");
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   116
	    }
325
claus
parents: 308
diff changeset
   117
    }
claus
parents: 308
diff changeset
   118
}
claus
parents: 308
diff changeset
   119
claus
parents: 308
diff changeset
   120
int
claus
parents: 308
diff changeset
   121
pclose(str)
claus
parents: 308
diff changeset
   122
FILE *str;
claus
parents: 308
diff changeset
   123
{
claus
parents: 308
diff changeset
   124
    int pd = 0;
claus
parents: 308
diff changeset
   125
    int status;
claus
parents: 308
diff changeset
   126
    int err;
claus
parents: 308
diff changeset
   127
claus
parents: 308
diff changeset
   128
    err = fclose(str);
claus
parents: 308
diff changeset
   129
claus
parents: 308
diff changeset
   130
    do {
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   131
	if ((pd = wait(&status)) == -1)
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   132
	{
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   133
		err = EOF;
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   134
		break;
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   135
	}
325
claus
parents: 308
diff changeset
   136
    } while (pd !=  popen_pid);
claus
parents: 308
diff changeset
   137
claus
parents: 308
diff changeset
   138
    if (err == EOF)
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   139
	return  -1;
325
claus
parents: 308
diff changeset
   140
claus
parents: 308
diff changeset
   141
    if (status)
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   142
	status >>= 8;   /* exit status in high byte */
325
claus
parents: 308
diff changeset
   143
claus
parents: 308
diff changeset
   144
    return status;
claus
parents: 308
diff changeset
   145
}
claus
parents: 308
diff changeset
   146
2925
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   147
#endif /* NEED_POPEN_WITH_VFORK */
325
claus
parents: 308
diff changeset
   148
claus
parents: 308
diff changeset
   149
%}
claus
parents: 308
diff changeset
   150
! !
claus
parents: 308
diff changeset
   151
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   152
!PipeStream class methodsFor:'documentation'!
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   153
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   154
copyright
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   155
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   156
 COPYRIGHT (c) 1989 by Claus Gittinger
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   157
	      All Rights Reserved
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   158
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   159
 This software is furnished under a license and may be used
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   160
 only in accordance with the terms of that license and with the
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   161
 inclusion of the above copyright notice.   This software may not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   162
 be provided or otherwise made available to, or used by, any
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   163
 other person.  No title to or ownership of the software is
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   164
 hereby transferred.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   165
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   166
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   167
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   168
documentation
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   169
"
17460
27b6fcc56477 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17077
diff changeset
   170
    Pipestreams allow reading or writing from/to a unix or dos command.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   171
    For example, to get a stream reading the output of an 'ls -l'
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   172
    command, a PipeStream can be created with:
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   173
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   174
        PipeStream readingFrom:'ls -l'
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   175
17460
27b6fcc56477 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17077
diff changeset
   176
    the characters of the command's output can be read using the
27b6fcc56477 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17077
diff changeset
   177
    standard stream messages, such as next, nextLine etc.
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   178
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   179
    Example for writing to a command:
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   180
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   181
        PipeStream writingTo:'cat >/tmp/x'
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   182
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   183
    Bidirectional pipestreams (supporting both reading an writing) may be used for filters:
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   184
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   185
        PipeStream bidirectionalFor:'sed -u -e ''s/Hello/Greetings/'''
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   186
1662
ce26ca3d837c linux stdio does not work with buffered pipes
Claus Gittinger <cg@exept.de>
parents: 1648
diff changeset
   187
    Buffered pipes do not work with Linux - the stdio library seems to be
ce26ca3d837c linux stdio does not work with buffered pipes
Claus Gittinger <cg@exept.de>
parents: 1648
diff changeset
   188
    buggy (trying to restart the read ...)
ce26ca3d837c linux stdio does not work with buffered pipes
Claus Gittinger <cg@exept.de>
parents: 1648
diff changeset
   189
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   190
    [author:]
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   191
        Claus Gittinger
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   192
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   193
    [see also:]
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   194
        ExternalStream FileStream Socket
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   195
        OperatingSystem
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   196
"
22975
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   197
!
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   198
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   199
examples
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   200
"
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   201
  reading:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   202
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   203
    |p output|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   204
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   205
    p := PipeStream readingFrom:'ls -l'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   206
    output := p upToEnd.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   207
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   208
    Transcript showCR:output
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   209
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   210
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   211
  bidirectional:
22992
0c18bba2b09a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22991
diff changeset
   212
  (must add a '-u' argument, because otherwise sed will read a big junk
0c18bba2b09a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22991
diff changeset
   213
  waiting for more input, before generating any output) 
0c18bba2b09a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22991
diff changeset
   214
  Notice: OSX sed does not support a '-u' option (sigh)
22975
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   215
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   216
    |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   217
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   218
    p := PipeStream bidirectionalFor:'sed -u -e s/Hello/Greetings/'.
22992
0c18bba2b09a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22991
diff changeset
   219
    p nextPutLine:'bla'.
22975
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   220
    Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   221
    p nextPutLine:'foo Hello'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   222
    Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   223
    p nextPutLine:'bar'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   224
    Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   225
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   226
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   227
                                                
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   228
  error output is on my stderr:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   229
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   230
    |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   231
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   232
    p := PipeStream readingFrom:'echo hello1; echo error>&2; echo hello2'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   233
    Transcript showCR:p upToEnd.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   234
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   235
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   236
                                                
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   237
  error output is included:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   238
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   239
    |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   240
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   241
    p := PipeStream readingFrom:'echo hello1; echo error>&2; echo hello2' errorDisposition:#stdout.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   242
    Transcript showCR:p upToEnd.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   243
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   244
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   245
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   246
  error output is separate:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   247
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   248
    |p errStream|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   249
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   250
    errStream := '' writeStream.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   251
    p := PipeStream readingFrom:'echo hello1; echo error>&2; echo hello2' errorDisposition:errStream.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   252
    Transcript showCR:'output:'; showCR:p upToEnd; cr.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   253
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   254
    Transcript showCR:'error:'; showCR:errStream contents; cr.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   255
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   256
"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   257
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   258
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   259
!PipeStream class methodsFor:'initialization'!
2
claus
parents: 1
diff changeset
   260
claus
parents: 1
diff changeset
   261
initialize
claus
parents: 1
diff changeset
   262
    "setup the signal"
claus
parents: 1
diff changeset
   263
57
db9677479d35 *** empty log message ***
claus
parents: 49
diff changeset
   264
    BrokenPipeSignal isNil ifTrue:[
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   265
	BrokenPipeSignal := WriteError newSignalMayProceed:true.
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   266
	BrokenPipeSignal nameClass:self message:#brokenPipeSignal.
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   267
	BrokenPipeSignal notifierString:'write on a pipe with no one to read'.
57
db9677479d35 *** empty log message ***
claus
parents: 49
diff changeset
   268
    ]
2
claus
parents: 1
diff changeset
   269
! !
claus
parents: 1
diff changeset
   270
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   271
!PipeStream class methodsFor:'instance creation'!
2
claus
parents: 1
diff changeset
   272
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   273
bidirectionalFor:commandString
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   274
    "create and return a new bidirectonal pipeStream which can both be written to
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   275
     and read from the unix command given by commandString.
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   276
     The commands error output is send to my own error output."
2
claus
parents: 1
diff changeset
   277
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   278
    ^ self
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   279
        bidirectionalFor:commandString
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   280
        errorDisposition:#stderr
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   281
        inDirectory:nil
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   282
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   283
    "
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   284
        |p|
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   285
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   286
        p := PipeStream bidirectionalFor:'cat -u'.
23041
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   287
        p nextPutAll:'Wer ist der Bürgermeister von Wesel'; cr.
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   288
        Transcript showCR:p nextLine.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   289
        p close
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   290
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   291
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   292
    "
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   293
        |p|
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   294
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   295
        p := PipeStream bidirectionalFor:'sed -u -e ''s/Hello/Greetings/'''.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   296
        p nextPutAll:'Hello world'; cr.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   297
        p shutDownOutput.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   298
        Transcript showCR:p nextLine.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   299
        p close
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   300
    "
9313
297699a317d3 comment/example
Stefan Vogel <sv@exept.de>
parents: 9193
diff changeset
   301
297699a317d3 comment/example
Stefan Vogel <sv@exept.de>
parents: 9193
diff changeset
   302
    "
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   303
        |p|
9313
297699a317d3 comment/example
Stefan Vogel <sv@exept.de>
parents: 9193
diff changeset
   304
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   305
        p := PipeStream bidirectionalFor:'wc'.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   306
        p nextPutAll:'Hello world'; cr.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   307
        p shutDownOutput.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   308
        Transcript showCR:p nextLine.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   309
        p close
9313
297699a317d3 comment/example
Stefan Vogel <sv@exept.de>
parents: 9193
diff changeset
   310
    "
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   311
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   312
    "Modified (comment): / 22-05-2018 / 10:46:32 / Stefan Vogel"
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   313
!
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   314
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   315
bidirectionalFor:commandString errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectory
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   316
    "create and return a new bidirectonal pipeStream which can both be written to
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   317
     and read from the unix command given by commandString.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   318
     The directory will be changed to aDirectory while
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   319
     executing the command. Use this if a command is to be
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   320
     executed in another directory, to avoid any OS dependencies
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   321
     in your code.
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   322
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   323
     errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   324
     #discard causes stderr to be discarded (/dev/null),
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   325
     #inline causes it to be written to smalltalk's own stdout
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   326
     #stderr causes it to be written to smalltalk's own stderr.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   327
     a stream causes stderr to be sent to that stream (internal or external)
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   328
     Nil is treated like #stderr"
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   329
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   330
    ^ self basicNew
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   331
        openPipeFor:commandString
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   332
        withMode:#'r+'
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   333
        errorDisposition:errorDispositionSymbolOrStream
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   334
        inDirectory:aDirectory
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   335
!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   336
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   337
readingFrom:commandString
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   338
    "create and return a new pipeStream which can read from the unix command
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   339
     given by commandString.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   340
     The command's error output is send to my own error output."
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   341
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   342
    ^ self
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   343
        readingFrom:commandString
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   344
        errorDisposition:#stderr
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   345
        inDirectory:nil
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   346
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   347
    "unix:
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   348
        PipeStream readingFrom:'ls -l'.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   349
    "
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   350
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   351
    "
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   352
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   353
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   354
        p := PipeStream readingFrom:'ls -l'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   355
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   356
        p close
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   357
    "
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   358
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   359
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   360
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   361
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   362
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   363
        p := PipeStream readingFrom:'echo error >&2'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   364
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   365
        p close
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   366
    "
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   367
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   368
    "
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   369
        |s|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   370
        s := PipeStream readingFrom:'sh -c sleep\ 600'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   371
        (Delay forSeconds:2) wait.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   372
        s abortAndClose
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   373
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   374
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   375
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   376
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   377
        p := PipeStream readingFrom:'dir'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   378
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   379
        p close
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   380
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   381
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   382
    "Windows:
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   383
        PipeStream readingFrom:'dir'.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   384
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   385
    "
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   386
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   387
        p := PipeStream readingFrom:'dir'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   388
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   389
        p close
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   390
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   391
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   392
    "Modified: 24.4.1996 / 09:09:25 / stefan"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   393
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   394
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   395
readingFrom:commandString environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   396
    "create and return a new pipeStream which can read from the unix command
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   397
     given by commandString.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   398
     The command's error output is send to my own error output."
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   399
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   400
    ^ self
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   401
        readingFrom:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   402
        errorDisposition:#stderr
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   403
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   404
        inDirectory:nil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   405
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   406
    "unix:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   407
        PipeStream readingFrom:'ls -l'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   408
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   409
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   410
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   411
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   412
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   413
        p := PipeStream readingFrom:'ls -l'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   414
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   415
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   416
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   417
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   418
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   419
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   420
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   421
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   422
        p := PipeStream readingFrom:'echo error >&2'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   423
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   424
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   425
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   426
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   427
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   428
        |s|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   429
        s := PipeStream readingFrom:'sh -c sleep\ 600'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   430
        (Delay forSeconds:2) wait.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   431
        s abortAndClose
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   432
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   433
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   434
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   435
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   436
        p := PipeStream readingFrom:'dir'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   437
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   438
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   439
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   440
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   441
    "Windows:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   442
        PipeStream readingFrom:'dir'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   443
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   444
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   445
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   446
        p := PipeStream readingFrom:'dir'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   447
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   448
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   449
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   450
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   451
    "Modified: 24.4.1996 / 09:09:25 / stefan"
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   452
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   453
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   454
readingFrom:commandString environment:aShellEnvironmentOrNil inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   455
    "similar to #readingFrom, but changes the directory while
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   456
     executing the command. Use this if a command is to be
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   457
     executed in another directory, to avoid any OS dependencies
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   458
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   459
     The command's error output is send to my own error output."
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   460
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   461
     ^ self
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   462
        readingFrom:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   463
        errorDisposition:#stderr
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   464
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   465
        inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   466
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   467
    " UNIX:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   468
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   469
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   470
        p := PipeStream readingFrom:'ls -l' inDirectory:'/etc'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   471
        Transcript showCR:p upToEnd.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   472
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   473
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   474
    "WINDOOF:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   475
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   476
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   477
        p := PipeStream readingFrom:'dir'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   478
        Transcript showCR:p upToEnd.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   479
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   480
   "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   481
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   482
22975
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   483
readingFrom:commandString errorDisposition:errorDispositionSymbolOrStream
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   484
    "create and return a new pipeStream which can read from the unix command
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   485
     given by commandString.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   486
     errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   487
       #discard causes stderr to be discarded (/dev/null),
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   488
       #inline causes it to be merged into the PipeStream and
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   489
       #stderr causes it to be written to smalltalk's own stderr.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   490
       a stream causes stderr to be sent to that stream (internal or external)
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   491
       Nil is treated like #stderr"
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   492
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   493
    ^ self
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   494
        readingFrom:commandString
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   495
        errorDisposition:errorDispositionSymbolOrStream
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   496
        inDirectory:nil
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   497
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   498
    "unix:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   499
        PipeStream readingFrom:'ls -l'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   500
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   501
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   502
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   503
        |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   504
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   505
        p := PipeStream readingFrom:'ls -l'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   506
        Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   507
        p close
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   508
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   509
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   510
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   511
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   512
        |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   513
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   514
        p := PipeStream readingFrom:'echo error >&2'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   515
        Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   516
        p close
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   517
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   518
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   519
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   520
        |s|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   521
        s := PipeStream readingFrom:'sh -c sleep\ 600'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   522
        (Delay forSeconds:2) wait.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   523
        s abortAndClose
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   524
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   525
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   526
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   527
        |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   528
        p := PipeStream readingFrom:'dir'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   529
        Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   530
        p close
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   531
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   532
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   533
    "Windows:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   534
        PipeStream readingFrom:'dir'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   535
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   536
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   537
        |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   538
        p := PipeStream readingFrom:'dir'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   539
        Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   540
        p close
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   541
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   542
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   543
    "Modified: 24.4.1996 / 09:09:25 / stefan"
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   544
!
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   545
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   546
readingFrom:commandString errorDisposition:errorDispositionSymbolOrStream environment:aShellEnvironmentOrNil inDirectory:aDirectory
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   547
    "similar to #readingFrom, but changes the directory while
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   548
     executing the command. Use this if a command is to be
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   549
     executed in another directory, to avoid any OS dependencies
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   550
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   551
     errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   552
       #discard causes stderr to be discarded (/dev/null),
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   553
       #inline causes it to be merged into the PipeStream and
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   554
       #stderr causes it to be written to smalltalk's own stderr.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   555
       a stream causes stderr to be sent to that stream (internal or external)
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   556
       Nil is treated like #stderr"
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   557
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   558
    ^ self basicNew
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   559
        openPipeFor:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   560
        withMode:#r
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   561
        errorDisposition:errorDispositionSymbolOrStream
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   562
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   563
        inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   564
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   565
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   566
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   567
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   568
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   569
        p := PipeStream readingFrom:'bla' errorDisposition:Transcript inDirectory:nil.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   570
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   571
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   572
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   573
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   574
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   575
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   576
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   577
        p := PipeStream readingFrom:'bla' errorDisposition:#inline inDirectory:nil.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   578
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   579
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   580
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   581
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   582
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   583
readingFrom:commandString errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectory
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   584
    "similar to #readingFrom, but changes the directory while
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   585
     executing the command. Use this if a command is to be
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   586
     executed in another directory, to avoid any OS dependencies
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   587
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   588
     errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   589
       #discard causes stderr to be discarded (/dev/null),
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   590
       #inline causes it to be merged into the PipeStream and
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   591
       #stderr causes it to be written to smalltalk's own stderr.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   592
       a stream causes stderr to be sent to that stream (internal or external)
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   593
       Nil is treated like #stderr"
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   594
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   595
    ^ self basicNew
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   596
        openPipeFor:commandString
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   597
        withMode:#r
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   598
        errorDisposition:errorDispositionSymbolOrStream
22993
cb633eae2834 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22992
diff changeset
   599
        environment:nil
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   600
        inDirectory:aDirectory
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   601
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   602
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   603
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   604
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   605
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   606
        p := PipeStream readingFrom:'bla' errorDisposition:Transcript inDirectory:nil.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   607
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   608
        p close
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   609
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   610
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   611
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   612
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   613
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   614
        p := PipeStream readingFrom:'bla' errorDisposition:#inline inDirectory:nil.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   615
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   616
        p close
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   617
    "
22993
cb633eae2834 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22992
diff changeset
   618
cb633eae2834 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22992
diff changeset
   619
    "Modified: / 22-05-2018 / 22:13:08 / Stefan Vogel"
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   620
!
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   621
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   622
readingFrom:commandString inDirectory:aDirectory
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   623
    "similar to #readingFrom, but changes the directory while
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   624
     executing the command. Use this if a command is to be
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   625
     executed in another directory, to avoid any OS dependencies
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   626
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   627
     The command's error output is send to my own error output."
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   628
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   629
     ^ self
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   630
        readingFrom:commandString
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   631
        errorDisposition:#stderr
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   632
        inDirectory:aDirectory
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   633
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   634
    " UNIX:
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   635
        |p|
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   636
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   637
        p := PipeStream readingFrom:'ls -l' inDirectory:'/etc'.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   638
        Transcript showCR:p upToEnd.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   639
        p close
9193
47ffbf7b9ee8 comment
Claus Gittinger <cg@exept.de>
parents: 8976
diff changeset
   640
    "
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   641
    "WINDOOF:
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   642
        |p|
9193
47ffbf7b9ee8 comment
Claus Gittinger <cg@exept.de>
parents: 8976
diff changeset
   643
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   644
        p := PipeStream readingFrom:'dir'.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   645
        Transcript showCR:p upToEnd.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   646
        p close
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   647
   "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   648
!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   649
2
claus
parents: 1
diff changeset
   650
writingTo:commandString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   651
    "create and return a new pipeStream which can write to the unix command
a27a279701f8 Initial revision
claus
parents:
diff changeset
   652
     given by command."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   653
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   654
    ^ self
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   655
	writingTo:commandString errorDisposition:#stderr inDirectory:nil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   656
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   657
    "unix:
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   658
	 PipeStream writingTo:'sort'
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   659
    "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   660
!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   661
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   662
writingTo:commandString environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   663
    "create and return a new pipeStream which can write to the unix command
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   664
     given by command."
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   665
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   666
    ^ self
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   667
        writingTo:commandString 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   668
        errorDisposition:#stderr 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   669
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   670
        inDirectory:nil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   671
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   672
    "unix:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   673
         PipeStream writingTo:'sort'
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   674
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   675
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   676
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   677
writingTo:commandString environment:aShellEnvironmentOrNil inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   678
    "create and return a new pipeStream which can write to the unix command
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   679
     given by commandString. The command is executed in the given directory."
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   680
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   681
    ^ self
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   682
        writingTo:commandString 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   683
        errorDisposition:#stderr 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   684
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   685
        inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   686
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   687
    "unix:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   688
         PipeStream writingTo:'sort'
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   689
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   690
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   691
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   692
writingTo:commandString errorDisposition:errorDispositionSymbolOrStream environment:aShellEnvironmentOrNil inDirectory:aDirectory
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   693
    "similar to #writingTo, but changes the directory while
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   694
     executing the command. Use this if a command is to be
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   695
     executed in another directory, to avoid any OS dependencies
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   696
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   697
     errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   698
       #discard causes stderr to be discarded (/dev/null),
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   699
       #inline causes it to be written to smalltalk's own stdout
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   700
       #stderr causes it to be written to smalltalk's own stderr.
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   701
       Nil is treated like #stderr"
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   702
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   703
    ^ self basicNew
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   704
        openPipeFor:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   705
        withMode:#w
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   706
        errorDisposition:errorDispositionSymbolOrStream
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   707
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   708
        inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   709
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   710
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   711
writingTo:commandString errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectory
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   712
    "similar to #writingTo, but changes the directory while
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   713
     executing the command. Use this if a command is to be
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   714
     executed in another directory, to avoid any OS dependencies
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   715
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   716
     errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   717
       #discard causes stderr to be discarded (/dev/null),
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   718
       #inline causes it to be written to smalltalk's own stdout
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   719
       #stderr causes it to be written to smalltalk's own stderr.
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   720
       Nil is treated like #stderr"
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   721
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   722
    ^ self basicNew
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   723
        openPipeFor:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   724
        withMode:#w
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   725
        errorDisposition:errorDispositionSymbolOrStream
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   726
        inDirectory:aDirectory
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   727
!
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   728
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   729
writingTo:commandString inDirectory:aDirectory
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   730
    "create and return a new pipeStream which can write to the unix command
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   731
     given by commandString. The command is executed in the given directory."
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   732
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   733
    ^ self
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   734
        writingTo:commandString 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   735
        errorDisposition:#stderr 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   736
        inDirectory:aDirectory
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   737
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   738
    "unix:
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   739
         PipeStream writingTo:'sort'
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   740
    "
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   741
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   742
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   743
!PipeStream class methodsFor:'Signal constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   744
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   745
brokenPipeSignal
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   746
    "return the signal used to handle SIGPIPE unix-signals.
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   747
     Since SIGPIPE is asynchronous, we can't decide which smalltalk process
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   748
     should handle BrokenPipeSignal. So the system doesn't raise
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   749
     BrokenPipeSignal for SIGPIPE any longer."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   750
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   751
    ^ BrokenPipeSignal
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   752
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   753
    "Modified: 24.9.1997 / 09:43:23 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   754
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   755
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   756
!PipeStream class methodsFor:'utilities'!
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   757
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   758
outputFromCommand:aCommand
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   759
    "open a pipe reading from aCommand and return the complete output as a string.
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   760
     If the command cannot be executed, return nil.
23041
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   761
     The command's current directory will be the smalltalk current directory.
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   762
     Only stdout is returned; stderr is ignored (sent to /dev/null)."
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   763
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   764
    ^ self outputFromCommand:aCommand inDirectory:nil
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   765
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   766
    "
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   767
     PipeStream outputFromCommand:'ls -l'
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   768
    "
23041
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   769
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   770
    "Modified (comment): / 31-05-2018 / 08:56:06 / Claus Gittinger"
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   771
!
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   772
23387
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   773
outputFromCommand:aCommand errorDisposition:errorDispositionSymbolOrStream 
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   774
    "open a pipe reading from aCommand and return the complete output as a string.
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   775
     If the command cannot be executed, return nil.
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   776
     The command will be executed in smalltalk's current directory.
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   777
     errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   778
       #discard causes stderr to be discarded (/dev/null),
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   779
       #inline causes it to be merged into the PipeStream and
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   780
       #stderr causes it to be written to smalltalk's own stderr.
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   781
       a stream causes stderr to be sent to that stream (internal or external)
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   782
       Nil is treated like #stderr"
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   783
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   784
    ^ self outputFromCommand:aCommand errorDisposition:errorDispositionSymbolOrStream inDirectory:nil
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   785
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   786
    "Created: / 25-09-2018 / 10:32:49 / Claus Gittinger"
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   787
!
ced9a63547cd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23041
diff changeset
   788
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   789
outputFromCommand:aCommand errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectoryOrNil
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   790
    "open a pipe reading from aCommand and return the complete output as a string.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   791
     If the command cannot be executed, return nil.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   792
     The current directory of the command will be aDirectoryOrNil 
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   793
     or the smalltalk's current directory (if nil).
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   794
     errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   795
       #discard causes stderr to be discarded (/dev/null),
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   796
       #inline causes it to be merged into the PipeStream and
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   797
       #stderr causes it to be written to smalltalk's own stderr.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   798
       a stream causes stderr to be sent to that stream (internal or external)
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   799
       Nil is treated like #stderr"
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   800
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   801
    |p cmdOutput|
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   802
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   803
    p := self readingFrom:aCommand errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectoryOrNil.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   804
    p isNil ifTrue:[^ nil].
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   805
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   806
    [
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   807
        cmdOutput := p contentsAsString.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   808
    ] ensure:[
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   809
        p close.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   810
    ].
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   811
    ^ cmdOutput
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   812
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   813
    "
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   814
     PipeStream outputFromCommand:'ls -l' inDirectory:nil
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   815
     PipeStream outputFromCommand:'ls -l' inDirectory:'/'
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   816
     PipeStream outputFromCommand:'ls -l' inDirectory:'/etc'
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   817
    "
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   818
!
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   819
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   820
outputFromCommand:aCommand inDirectory:aDirectoryOrNil
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   821
    "open a pipe reading from aCommand and return the complete output as a string.
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   822
     If the command cannot be executed, return nil.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   823
     The current directory of the command will be aDirectoryOrNil 
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   824
     or the smalltalk's current directory (if nil).
23041
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   825
     Any stderr output will be discarded (not included) in the returned cmdOutput."
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   826
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   827
    |p cmdOutput|
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   828
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   829
    p := self readingFrom:aCommand inDirectory:aDirectoryOrNil.
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   830
    p isNil ifTrue:[^ nil].
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   831
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   832
    [
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   833
        cmdOutput := p contentsAsString.
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   834
    ] ensure:[
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   835
        p close.
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   836
    ].
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   837
    ^ cmdOutput
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   838
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   839
    "
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   840
     PipeStream outputFromCommand:'ls -l' inDirectory:nil
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   841
     PipeStream outputFromCommand:'ls -l' inDirectory:'/'
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   842
     PipeStream outputFromCommand:'ls -l' inDirectory:'/etc'
23041
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   843
     PipeStream outputFromCommand:'echo hello >&2' inDirectory:'/etc'
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   844
    "
23041
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   845
9495bc3c0d0d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22993
diff changeset
   846
    "Modified (comment): / 31-05-2018 / 08:57:04 / Claus Gittinger"
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   847
! !
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   848
99
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   849
!PipeStream methodsFor:'accessing'!
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   850
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   851
commandString
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   852
    "return the command string"
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   853
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   854
    ^ commandString
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   855
!
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   856
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   857
exitStatus
10343
c48f0a54ef69 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9313
diff changeset
   858
    "return the exitStatus"
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   859
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   860
    osProcess isNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   861
        ^ nil.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   862
    ].
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   863
    ^ osProcess exitStatus.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   864
    
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   865
    "Created: 28.12.1995 / 14:54:41 / stefan"
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   866
!
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   867
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   868
pid
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   869
    "return pid"
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   870
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   871
    osProcess isNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   872
        ^ nil.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   873
    ].
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   874
    ^ osProcess pid.
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   875
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   876
    "Created: 28.12.1995 / 14:54:30 / stefan"
23484
a17be8a2cf05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23387
diff changeset
   877
!
a17be8a2cf05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23387
diff changeset
   878
a17be8a2cf05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23387
diff changeset
   879
setCommandString:aString
a17be8a2cf05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23387
diff changeset
   880
    "for OSProcess only (so we see the command in the streams monitor)"
a17be8a2cf05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23387
diff changeset
   881
a17be8a2cf05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23387
diff changeset
   882
    commandString := aString
a17be8a2cf05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23387
diff changeset
   883
a17be8a2cf05 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23387
diff changeset
   884
    "Created: / 29-10-2018 / 15:14:24 / Claus Gittinger"
99
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   885
! !
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   886
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   887
!PipeStream methodsFor:'closing'!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   888
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   889
abortAndClose
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   890
    "close the Stream and terminate the command"
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   891
20031
8de79de4b866 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   892
    self unregisterForFinalization.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   893
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   894
    "terminate first under windows"
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   895
    OperatingSystem isMSDOSlike ifTrue:[
20031
8de79de4b866 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   896
        self terminatePipeCommand.
21228
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
   897
        self closeFile.
20031
8de79de4b866 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   898
        ^ self.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   899
    ].
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   900
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   901
    "terminate last under unix"
21228
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
   902
    self closeFile.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   903
    self terminatePipeCommand.
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   904
!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   905
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   906
close
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   907
    "low level close
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   908
     This waits for the command to finish.
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   909
     Use abortAndClose for a fast (nonBlocking) close."
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   910
22696
7b933d672ea3 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22507
diff changeset
   911
    self isOpen ifTrue:[
22991
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   912
        self shutDownOutput.
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   913
        super close.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   914
        "/ wait for the pipe-command to terminate.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   915
        self waitForPipeCommandWithTimeout:nil.
22991
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   916
"/ Maybe later, currently senders have to retrieve exitstatus manually:
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   917
"/        osProcess finishedWithSuccess ifFalse:[
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   918
"/            exitStatus := osProcess exitStatus.
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   919
"/            StreamError raiseRequestWith:exitStatus errorString:'pipe command failed with exit code: ', exitStatus code printString.
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   920
"/        ].
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   921
    ].
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   922
22696
7b933d672ea3 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22507
diff changeset
   923
    "Modified: / 12-09-1998 / 16:51:04 / cg"
7b933d672ea3 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22507
diff changeset
   924
    "Modified: / 23-04-2018 / 18:25:04 / stefan"
22991
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   925
    "Modified (comment): / 22-05-2018 / 17:48:15 / Stefan Vogel"
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   926
!
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   927
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   928
shutDown
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   929
    <resource: #obsolete>
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   930
    "this is a historic leftover kept for backward compatibility.
20970
54cb5bc5bd05 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20681
diff changeset
   931
     The name collides with the same name in Socket, which does
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   932
     not hard terminate the connection."
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   933
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   934
    self abortAndClose.
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   935
!
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   936
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   937
shutDownOutput
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   938
    "signal to the pipestream's command, that no more data will be sent"
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   939
8976
2ff451956d48 #shutDownOutput do nothing (ignore errors), if pipe is closed
Stefan Vogel <sv@exept.de>
parents: 8969
diff changeset
   940
    |fd|
2ff451956d48 #shutDownOutput do nothing (ignore errors), if pipe is closed
Stefan Vogel <sv@exept.de>
parents: 8969
diff changeset
   941
22991
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   942
    (self isOpen and:[mode ~~ #readonly]) ifTrue:[
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   943
        self flush.
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   944
        fd := self fileDescriptor.
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   945
        fd notNil ifTrue:[
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   946
            OperatingSystem shutdownBidirectionalPipeOutput:fd.
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   947
        ].
8976
2ff451956d48 #shutDownOutput do nothing (ignore errors), if pipe is closed
Stefan Vogel <sv@exept.de>
parents: 8969
diff changeset
   948
    ].
22991
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   949
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
   950
    "Modified: / 22-05-2018 / 18:34:28 / Stefan Vogel"
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   951
! !
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   952
5243
d3b509746522 category change
Claus Gittinger <cg@exept.de>
parents: 5205
diff changeset
   953
!PipeStream methodsFor:'finalization'!
d3b509746522 category change
Claus Gittinger <cg@exept.de>
parents: 5205
diff changeset
   954
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6267
diff changeset
   955
finalize
5243
d3b509746522 category change
Claus Gittinger <cg@exept.de>
parents: 5205
diff changeset
   956
    "redefined to avoid blocking in close."
d3b509746522 category change
Claus Gittinger <cg@exept.de>
parents: 5205
diff changeset
   957
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   958
    self abortAndClose
18785
5b58b205c252 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18782
diff changeset
   959
! !
5b58b205c252 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18782
diff changeset
   960
5b58b205c252 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18782
diff changeset
   961
!PipeStream methodsFor:'private'!
369
claus
parents: 362
diff changeset
   962
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   963
openPipeFor:aCommandString withMode:rwMode errorDisposition:errorDisposition 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   964
    environment:aShellEnvironmentOrNil inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   965
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   966
    "open a pipe to the OS command in commandString;
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   967
     rwMode may be 'r' or 'w' or 'r+'.
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   968
5481
680d6de80808 comment
Claus Gittinger <cg@exept.de>
parents: 5456
diff changeset
   969
     errorDisposition controls where the stdErr output should go,
680d6de80808 comment
Claus Gittinger <cg@exept.de>
parents: 5456
diff changeset
   970
     and may be one of #discard, #inline or #stderr (default).
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   971
       #discard causes stderr to be discarded (/dev/null),
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   972
       #inline causes it to be written to smalltalks own stdout and
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   973
       #stderr causes it to be written to smalltalks own stderr.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   974
       Nil is treated like #stderr."
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   975
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   976
    |pipeArray remotePipeEnd nullOutput errorNumber myPipeEnd result|
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   977
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 11083
diff changeset
   978
    handle notNil ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   979
        "the pipe was already open ...
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   980
         this should (can) not happen."
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   981
        ^ self errorAlreadyOpen
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   982
    ].
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   983
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   984
    rwMode = #r ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   985
        mode := #readonly. didWrite := false.
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   986
        position := 0.      "only reading - can keep track of position"
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   987
    ] ifFalse:[rwMode = #'r+' ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   988
        mode := #readwrite. didWrite := true.
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   989
    ] ifFalse:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   990
        mode := #writeonly. didWrite := true.
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   991
        position := 0.      "only writing - can keep track of position"
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   992
    ]].
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   993
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   994
    lastErrorNumber := nil.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   995
    commandString := aCommandString.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   996
    "stdio lib does not work with blocking pipes and interrupts
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   997
     for WIN, Linux, Solaris and probably any other UNIX"
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   998
    buffered := false.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   999
    hitEOF := false.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1000
    binary := false.
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
  1001
21791
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1002
    osProcess := OSProcess new
22440
a5f9b3aed756 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21791
diff changeset
  1003
                    command:aCommandString directory:aDirectory.
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1004
    aShellEnvironmentOrNil notNil ifTrue:[
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1005
        osProcess environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1006
    ].
4616
64dd3a9bebf5 *** empty log message ***
ps
parents: 4526
diff changeset
  1007
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1008
    mode == #readwrite ifTrue:[
21211
ed5fd0f7a98b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21210
diff changeset
  1009
        pipeArray := self class makeBidirectionalPipe.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1010
        pipeArray isNil ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1011
            lastErrorNumber := errorNumber := OperatingSystem currentErrorNumber.
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1012
            ^ self openError:errorNumber.
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1013
        ].
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1014
        myPipeEnd := pipeArray at:1.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1015
        remotePipeEnd := pipeArray at:2.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1016
        osProcess inStream:remotePipeEnd.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1017
        osProcess outStream:remotePipeEnd.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1018
    ] ifFalse:[
21211
ed5fd0f7a98b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21210
diff changeset
  1019
        pipeArray := self class makePipe.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1020
        pipeArray isNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1021
            lastErrorNumber := errorNumber := OperatingSystem currentErrorNumber.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1022
            ^ self openError:errorNumber.
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1023
        ].
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
  1024
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1025
        mode == #readonly ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1026
            "redirect stdout of subprocess to write to pipe"
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1027
            myPipeEnd := pipeArray at:1.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1028
            remotePipeEnd := pipeArray at:2.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1029
            osProcess outStream:remotePipeEnd.
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1030
        ] ifFalse:[
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1031
            "redirect stdin of subprocess to read from pipe"
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1032
            myPipeEnd := pipeArray at:2.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1033
            remotePipeEnd := pipeArray at:1.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1034
            osProcess inStream:remotePipeEnd.
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1035
        ].
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1036
    ].
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1037
7079
07625dfffcbf Cleanup filedescriptor closing on #exec:withArguments:....
Stefan Vogel <sv@exept.de>
parents: 7060
diff changeset
  1038
    errorDisposition == #discard ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1039
        nullOutput := Filename nullDevice writeStream.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1040
        osProcess errorStream:nullOutput.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1041
    ] ifFalse:[(errorDisposition == #inline or:[errorDisposition == #stdout]) ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1042
        osProcess errorStream:osProcess outStream.
21211
ed5fd0f7a98b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21210
diff changeset
  1043
    ] ifFalse:[(errorDisposition == #stderr or:[errorDisposition isNil]) ifTrue:[
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1044
        osProcess errorStream:Stderr.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1045
    ] ifFalse:[errorDisposition isStream ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1046
        osProcess errorStream:errorDisposition.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1047
    ]]]].
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1048
21228
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1049
    mode ~~ #readonly ifTrue:[
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1050
        osProcess terminateActionBlock:[
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1051
                "writing doesn't make sense - there is no reader any longer"
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1052
                mode == #readwrite ifTrue:[
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1053
                    "... but allow to read the rest of the command's output"
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1054
                    self shutDownOutput.
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1055
                ] ifFalse:[mode == #writeonly ifTrue:[
23878
a08a25c24390 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23484
diff changeset
  1056
                    self unregisterForFinalization.
21228
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1057
                    self closeFile.
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1058
                ]].
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1059
           ].
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1060
    ].
8969
978613904d0b For writing Pipestreams: close write side of filedescriptor, when
Stefan Vogel <sv@exept.de>
parents: 8968
diff changeset
  1061
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1062
    result := osProcess startProcess.
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1063
7079
07625dfffcbf Cleanup filedescriptor closing on #exec:withArguments:....
Stefan Vogel <sv@exept.de>
parents: 7060
diff changeset
  1064
    "subprocess has been created.
07625dfffcbf Cleanup filedescriptor closing on #exec:withArguments:....
Stefan Vogel <sv@exept.de>
parents: 7060
diff changeset
  1065
     close unused filedescriptors"
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1066
    remotePipeEnd notNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1067
        remotePipeEnd close.
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
  1068
    ].
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
  1069
    nullOutput notNil ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1070
        nullOutput close
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1071
    ].
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1072
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1073
    result ifTrue:[
21791
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1074
        "successful creation of subprocess"
21231
985ae4f2c424 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21228
diff changeset
  1075
        handle := myPipeEnd handle.
985ae4f2c424 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21228
diff changeset
  1076
        handleType := myPipeEnd handleType.
22507
eb40c1d02504 #DOCUMENTATION by mawalch
mawalch
parents: 22440
diff changeset
  1077
        myPipeEnd unregisterForFinalization.    "make sure filedescriptor is not closed by finalizer"
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1078
        myPipeEnd := nil.
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1079
    ] ifFalse:[
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1080
        "the pipe open failed for some reason ...
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1081
         ... this may be either due to an invalid command string,
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1082
         or due to the system running out of memory (when forking
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1083
         the unix process)"
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1084
        lastErrorNumber := OperatingSystem lastErrorNumber.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1085
        myPipeEnd close.
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1086
        ^ self openError:lastErrorNumber.
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1087
    ].
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1088
18782
aa9e2cb1d490 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18638
diff changeset
  1089
    self registerForFinalization.
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1090
21791
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1091
    "Modified: / 23-04-1996 / 17:05:59 / stefan"
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1092
    "Modified: / 28-01-1998 / 14:47:34 / md"
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1093
    "Created: / 19-05-1999 / 12:28:54 / cg"
22507
eb40c1d02504 #DOCUMENTATION by mawalch
mawalch
parents: 22440
diff changeset
  1094
    "Modified (comment): / 25-01-2018 / 19:40:27 / mawalch"
23878
a08a25c24390 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23484
diff changeset
  1095
    "Modified: / 12-03-2019 / 22:03:02 / Claus Gittinger"
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1096
!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1097
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1098
openPipeFor:aCommandString withMode:rwMode errorDisposition:errorDisposition inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1099
    "open a pipe to the OS command in commandString;
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1100
     rwMode may be 'r' or 'w' or 'r+'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1101
     errorDisposition controls where the stdErr output should go,
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1102
     and may be one of #discard, #inline or #stderr (default).
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1103
     #discard causes stderr to be discarded (/dev/null),
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1104
     #inline causes it to be written to smalltalks own stdout and
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1105
     #stderr causes it to be written to smalltalks own stderr.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1106
     Nil is treated like #stderr"
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1107
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1108
    ^ self 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1109
        openPipeFor:aCommandString withMode:rwMode errorDisposition:errorDisposition 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1110
        environment:nil inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1111
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1112
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1113
terminatePipeCommand
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1114
    osProcess notNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1115
        osProcess terminateGroup.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1116
    ].
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1117
!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1118
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1119
waitForPipeCommandWithTimeout:seconds
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1120
    "wait for the pipe command to terminate itself.
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1121
     Return true, if a timeout occurred."
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1122
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1123
    osProcess notNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1124
        ^ osProcess finishSema waitWithTimeout:seconds.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1125
    ].
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1126
    ^ false
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6267
diff changeset
  1127
! !
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
  1128
22980
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1129
!PipeStream methodsFor:'testing'!
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1130
22991
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
  1131
finishedWithSuccess
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
  1132
    ^ osProcess notNil and:[osProcess finishedWithSuccess].
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
  1133
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
  1134
    "Created: / 22-05-2018 / 18:17:11 / Stefan Vogel"
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
  1135
!
761301acd1aa #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22982
diff changeset
  1136
22980
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1137
isPipeStream
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1138
    ^ true
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1139
! !
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1140
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
  1141
!PipeStream class methodsFor:'documentation'!
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1142
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1143
version
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
  1144
    ^ '$Header$'
12712
c1b3b5846541 Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents: 12548
diff changeset
  1145
!
c1b3b5846541 Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents: 12548
diff changeset
  1146
c1b3b5846541 Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents: 12548
diff changeset
  1147
version_CVS
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
  1148
    ^ '$Header$'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1149
! !
7027
0efa9d55fa04 Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6487
diff changeset
  1150
15359
060c677e3e92 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 14436
diff changeset
  1151
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
  1152
PipeStream initialize!