PipeStream.st
author Stefan Vogel <sv@exept.de>
Tue, 22 May 2018 10:48:26 +0200
changeset 22982 c91015b9e2e3
parent 22980 8ea9d4f9983a
child 22991 761301acd1aa
permissions -rw-r--r--
#DOCUMENTATION by stefan class: PipeStream Fix bidirectionalPipe examples: sed needs -u option (unbufferd)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22696
7b933d672ea3 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22507
diff changeset
     1
"{ Encoding: utf8 }"
7b933d672ea3 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22507
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:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   212
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   213
    |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   214
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   215
    p := PipeStream bidirectionalFor:'sed -u -e s/Hello/Greetings/'.
22975
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   216
    p nextPutLine:'bla'; flush.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   217
    Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   218
    p nextPutLine:'foo Hello'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   219
    Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   220
    p nextPutLine:'bar'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   221
    Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   222
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   223
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   224
                                                
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   225
  error output is on my stderr:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   226
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   227
    |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   228
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   229
    p := PipeStream readingFrom:'echo hello1; echo error>&2; echo hello2'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   230
    Transcript showCR:p upToEnd.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   231
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   232
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   233
                                                
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   234
  error output is included:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   235
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   236
    |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   237
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   238
    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
   239
    Transcript showCR:p upToEnd.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   240
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   241
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   242
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   243
  error output is separate:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   244
                                                    [exBegin]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   245
    |p errStream|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   246
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   247
    errStream := '' writeStream.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   248
    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
   249
    Transcript showCR:'output:'; showCR:p upToEnd; cr.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   250
    p close.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   251
    Transcript showCR:'error:'; showCR:errStream contents; cr.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   252
                                                    [exEnd]
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   253
"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   254
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   255
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   256
!PipeStream class methodsFor:'initialization'!
2
claus
parents: 1
diff changeset
   257
claus
parents: 1
diff changeset
   258
initialize
claus
parents: 1
diff changeset
   259
    "setup the signal"
claus
parents: 1
diff changeset
   260
57
db9677479d35 *** empty log message ***
claus
parents: 49
diff changeset
   261
    BrokenPipeSignal isNil ifTrue:[
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   262
	BrokenPipeSignal := WriteError newSignalMayProceed:true.
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   263
	BrokenPipeSignal nameClass:self message:#brokenPipeSignal.
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   264
	BrokenPipeSignal notifierString:'write on a pipe with no one to read'.
57
db9677479d35 *** empty log message ***
claus
parents: 49
diff changeset
   265
    ]
2
claus
parents: 1
diff changeset
   266
! !
claus
parents: 1
diff changeset
   267
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   268
!PipeStream class methodsFor:'instance creation'!
2
claus
parents: 1
diff changeset
   269
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   270
bidirectionalFor:commandString
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   271
    "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
   272
     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
   273
     The commands error output is send to my own error output."
2
claus
parents: 1
diff changeset
   274
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   275
    ^ self
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   276
        bidirectionalFor:commandString
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   277
        errorDisposition:#stderr
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   278
        inDirectory:nil
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   279
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   280
    "
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   281
        |p|
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   282
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   283
        p := PipeStream bidirectionalFor:'cat -u'.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   284
        p nextPutAll:'Wer ist der Bürgermeister von Wesel'; cr.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   285
        Transcript showCR:p nextLine.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   286
        p close
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   287
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   288
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   289
    "
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   290
        |p|
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   291
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   292
        p := PipeStream bidirectionalFor:'sed -u -e ''s/Hello/Greetings/'''.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   293
        p nextPutAll:'Hello world'; cr.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   294
        p shutDownOutput.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   295
        Transcript showCR:p nextLine.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   296
        p close
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   297
    "
9313
297699a317d3 comment/example
Stefan Vogel <sv@exept.de>
parents: 9193
diff changeset
   298
297699a317d3 comment/example
Stefan Vogel <sv@exept.de>
parents: 9193
diff changeset
   299
    "
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   300
        |p|
9313
297699a317d3 comment/example
Stefan Vogel <sv@exept.de>
parents: 9193
diff changeset
   301
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   302
        p := PipeStream bidirectionalFor:'wc'.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   303
        p nextPutAll:'Hello world'; cr.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   304
        p shutDownOutput.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   305
        Transcript showCR:p nextLine.
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   306
        p close
9313
297699a317d3 comment/example
Stefan Vogel <sv@exept.de>
parents: 9193
diff changeset
   307
    "
22982
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   308
c91015b9e2e3 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22980
diff changeset
   309
    "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
   310
!
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   311
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   312
bidirectionalFor:commandString errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectory
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   313
    "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
   314
     and read from the unix command given by commandString.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   315
     The directory will be changed to aDirectory while
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   316
     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
   317
     executed in another directory, to avoid any OS dependencies
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   318
     in your code.
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   319
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   320
     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
   321
     #discard causes stderr to be discarded (/dev/null),
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   322
     #inline causes it to be written to smalltalk's own stdout
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   323
     #stderr causes it to be written to smalltalk's own stderr.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   324
     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
   325
     Nil is treated like #stderr"
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   326
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   327
    ^ self basicNew
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   328
        openPipeFor:commandString
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   329
        withMode:#'r+'
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   330
        errorDisposition:errorDispositionSymbolOrStream
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   331
        inDirectory:aDirectory
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   332
!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   333
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   334
readingFrom:commandString
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   335
    "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
   336
     given by commandString.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   337
     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
   338
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   339
    ^ self
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   340
        readingFrom:commandString
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   341
        errorDisposition:#stderr
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   342
        inDirectory:nil
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   343
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   344
    "unix:
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   345
        PipeStream readingFrom:'ls -l'.
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
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   348
    "
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   349
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   350
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   351
        p := PipeStream readingFrom:'ls -l'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   352
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   353
        p close
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   354
    "
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   355
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   356
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   357
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   358
        |p|
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
        p := PipeStream readingFrom:'echo error >&2'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   361
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   362
        p close
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   363
    "
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   364
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   365
    "
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   366
        |s|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   367
        s := PipeStream readingFrom:'sh -c sleep\ 600'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   368
        (Delay forSeconds:2) wait.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   369
        s abortAndClose
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   370
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   371
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   372
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   373
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   374
        p := PipeStream readingFrom:'dir'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   375
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   376
        p close
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   377
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   378
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   379
    "Windows:
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   380
        PipeStream readingFrom:'dir'.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   381
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   382
    "
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   383
        |p|
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   384
        p := PipeStream readingFrom:'dir'.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   385
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   386
        p close
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   387
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   388
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   389
    "Modified: 24.4.1996 / 09:09:25 / stefan"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   390
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   391
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   392
readingFrom:commandString environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   393
    "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
   394
     given by commandString.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   395
     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
   396
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   397
    ^ self
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   398
        readingFrom:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   399
        errorDisposition:#stderr
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   400
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   401
        inDirectory:nil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   402
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   403
    "unix:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   404
        PipeStream readingFrom:'ls -l'.
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
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   407
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   408
        |p|
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
        p := PipeStream readingFrom:'ls -l'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   411
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   412
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   413
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   414
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   415
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
        |p|
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
        p := PipeStream readingFrom:'echo error >&2'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   420
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   421
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   422
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   423
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   424
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   425
        |s|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   426
        s := PipeStream readingFrom:'sh -c sleep\ 600'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   427
        (Delay forSeconds:2) wait.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   428
        s abortAndClose
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   429
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   430
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   431
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   432
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   433
        p := PipeStream readingFrom:'dir'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   434
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   435
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   436
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   437
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   438
    "Windows:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   439
        PipeStream readingFrom:'dir'.
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
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   442
        |p|
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   443
        p := PipeStream readingFrom:'dir'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   444
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   445
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   446
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   447
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   448
    "Modified: 24.4.1996 / 09:09:25 / stefan"
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
readingFrom:commandString environment:aShellEnvironmentOrNil inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   452
    "similar to #readingFrom, but changes the directory while
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   453
     executing the command. Use this if a command is to be
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   454
     executed in another directory, to avoid any OS dependencies
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   455
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   456
     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
   457
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   458
     ^ self
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   459
        readingFrom:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   460
        errorDisposition:#stderr
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   461
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   462
        inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   463
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   464
    " UNIX:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   465
        |p|
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
        p := PipeStream readingFrom:'ls -l' inDirectory:'/etc'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   468
        Transcript showCR:p upToEnd.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   469
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   470
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   471
    "WINDOOF:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   472
        |p|
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
        p := PipeStream readingFrom:'dir'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   475
        Transcript showCR:p upToEnd.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   476
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   477
   "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   478
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   479
22975
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   480
readingFrom:commandString errorDisposition:errorDispositionSymbolOrStream
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   481
    "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
   482
     given by commandString.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   483
     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
   484
       #discard causes stderr to be discarded (/dev/null),
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   485
       #inline causes it to be merged into the PipeStream and
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   486
       #stderr causes it to be written to smalltalk's own stderr.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   487
       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
   488
       Nil is treated like #stderr"
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   489
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   490
    ^ self
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   491
        readingFrom:commandString
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   492
        errorDisposition:errorDispositionSymbolOrStream
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   493
        inDirectory:nil
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   494
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   495
    "unix:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   496
        PipeStream readingFrom:'ls -l'.
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
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   499
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   500
        |p|
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
        p := PipeStream readingFrom:'ls -l'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   503
        Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   504
        p close
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   505
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   506
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   507
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
        |p|
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
        p := PipeStream readingFrom:'echo error >&2'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   512
        Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   513
        p close
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   514
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   515
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   516
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   517
        |s|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   518
        s := PipeStream readingFrom:'sh -c sleep\ 600'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   519
        (Delay forSeconds:2) wait.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   520
        s abortAndClose
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   521
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   522
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   523
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   524
        |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   525
        p := PipeStream readingFrom:'dir'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   526
        Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   527
        p close
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   528
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   529
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   530
    "Windows:
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   531
        PipeStream readingFrom:'dir'.
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
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   534
        |p|
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   535
        p := PipeStream readingFrom:'dir'.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   536
        Transcript showCR:p nextLine.
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   537
        p close
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   538
    "
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   539
6b24e729a7d9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22974
diff changeset
   540
    "Modified: 24.4.1996 / 09:09:25 / stefan"
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
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   543
readingFrom:commandString errorDisposition:errorDispositionSymbolOrStream environment:aShellEnvironmentOrNil inDirectory:aDirectory
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   544
    "similar to #readingFrom, but changes the directory while
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   545
     executing the command. Use this if a command is to be
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   546
     executed in another directory, to avoid any OS dependencies
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   547
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   548
     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
   549
       #discard causes stderr to be discarded (/dev/null),
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   550
       #inline causes it to be merged into the PipeStream and
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   551
       #stderr causes it to be written to smalltalk's own stderr.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   552
       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
   553
       Nil is treated like #stderr"
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   554
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   555
    ^ self basicNew
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   556
        openPipeFor:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   557
        withMode:#r
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   558
        errorDisposition:errorDispositionSymbolOrStream
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   559
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   560
        inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   561
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   562
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   563
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   564
        |p|
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
        p := PipeStream readingFrom:'bla' errorDisposition:Transcript inDirectory:nil.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   567
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   568
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   569
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   570
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   571
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   572
        |p|
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
        p := PipeStream readingFrom:'bla' errorDisposition:#inline inDirectory:nil.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   575
        Transcript showCR:p nextLine.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   576
        p close
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   577
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   578
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   579
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   580
readingFrom:commandString errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectory
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   581
    "similar to #readingFrom, but changes the directory while
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   582
     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
   583
     executed in another directory, to avoid any OS dependencies
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   584
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   585
     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
   586
       #discard causes stderr to be discarded (/dev/null),
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   587
       #inline causes it to be merged into the PipeStream and
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   588
       #stderr causes it to be written to smalltalk's own stderr.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   589
       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
   590
       Nil is treated like #stderr"
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   591
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   592
    ^ self basicNew
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   593
        openPipeFor:commandString
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   594
        withMode:#r
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   595
        errorDisposition:errorDispositionSymbolOrStream
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   596
        inDirectory:aDirectory
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   597
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   598
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   599
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   600
        |p|
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
        p := PipeStream readingFrom:'bla' errorDisposition:Transcript inDirectory:nil.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   603
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   604
        p close
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
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   607
    "
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   608
        |p|
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
        p := PipeStream readingFrom:'bla' errorDisposition:#inline inDirectory:nil.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   611
        Transcript showCR:p nextLine.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   612
        p close
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   613
    "
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   614
!
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   615
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   616
readingFrom:commandString inDirectory:aDirectory
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   617
    "similar to #readingFrom, but changes the directory while
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   618
     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
   619
     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
   620
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   621
     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
   622
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   623
     ^ self
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   624
        readingFrom:commandString
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   625
        errorDisposition:#stderr
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   626
        inDirectory:aDirectory
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   627
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   628
    " UNIX:
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   629
        |p|
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   630
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   631
        p := PipeStream readingFrom:'ls -l' inDirectory:'/etc'.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   632
        Transcript showCR:p upToEnd.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   633
        p close
9193
47ffbf7b9ee8 comment
Claus Gittinger <cg@exept.de>
parents: 8976
diff changeset
   634
    "
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   635
    "WINDOOF:
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   636
        |p|
9193
47ffbf7b9ee8 comment
Claus Gittinger <cg@exept.de>
parents: 8976
diff changeset
   637
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   638
        p := PipeStream readingFrom:'dir'.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   639
        Transcript showCR:p upToEnd.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   640
        p close
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   641
   "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   642
!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   643
2
claus
parents: 1
diff changeset
   644
writingTo:commandString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   645
    "create and return a new pipeStream which can write to the unix command
a27a279701f8 Initial revision
claus
parents:
diff changeset
   646
     given by command."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   647
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   648
    ^ self
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   649
	writingTo:commandString errorDisposition:#stderr inDirectory:nil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   650
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   651
    "unix:
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   652
	 PipeStream writingTo:'sort'
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   653
    "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   654
!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   655
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   656
writingTo:commandString environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   657
    "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
   658
     given by command."
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   659
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   660
    ^ self
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   661
        writingTo:commandString 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   662
        errorDisposition:#stderr 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   663
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   664
        inDirectory:nil
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
    "unix:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   667
         PipeStream writingTo:'sort'
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   668
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   669
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   670
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   671
writingTo:commandString environment:aShellEnvironmentOrNil inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   672
    "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
   673
     given by commandString. The command is executed in the given directory."
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
    ^ self
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   676
        writingTo:commandString 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   677
        errorDisposition:#stderr 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   678
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   679
        inDirectory:aDirectory
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
    "unix:
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   682
         PipeStream writingTo:'sort'
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   683
    "
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   684
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   685
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   686
writingTo:commandString errorDisposition:errorDispositionSymbolOrStream environment:aShellEnvironmentOrNil inDirectory:aDirectory
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   687
    "similar to #writingTo, but changes the directory while
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   688
     executing the command. Use this if a command is to be
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   689
     executed in another directory, to avoid any OS dependencies
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   690
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   691
     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
   692
       #discard causes stderr to be discarded (/dev/null),
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   693
       #inline causes it to be written to smalltalk's own stdout
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   694
       #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
   695
       Nil is treated like #stderr"
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   696
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   697
    ^ self basicNew
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   698
        openPipeFor:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   699
        withMode:#w
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   700
        errorDisposition:errorDispositionSymbolOrStream
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   701
        environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   702
        inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   703
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   704
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   705
writingTo:commandString errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectory
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   706
    "similar to #writingTo, but changes the directory while
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   707
     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
   708
     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
   709
     in your code.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   710
     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
   711
       #discard causes stderr to be discarded (/dev/null),
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   712
       #inline causes it to be written to smalltalk's own stdout
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   713
       #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
   714
       Nil is treated like #stderr"
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   715
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   716
    ^ self basicNew
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   717
        openPipeFor:commandString
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   718
        withMode:#w
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   719
        errorDisposition:errorDispositionSymbolOrStream
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   720
        inDirectory:aDirectory
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   721
!
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   722
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   723
writingTo:commandString inDirectory:aDirectory
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   724
    "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
   725
     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
   726
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   727
    ^ self
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   728
        writingTo:commandString 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   729
        errorDisposition:#stderr 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   730
        inDirectory:aDirectory
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   731
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   732
    "unix:
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   733
         PipeStream writingTo:'sort'
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4202
diff changeset
   734
    "
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   735
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   736
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   737
!PipeStream class methodsFor:'Signal constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   738
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   739
brokenPipeSignal
2985
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   740
    "return the signal used to handle SIGPIPE unix-signals.
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   741
     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
   742
     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
   743
     BrokenPipeSignal for SIGPIPE any longer."
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
eff9e86dd2f9 New method #readingFrom:errorDisposition:inDirectory.
Stefan Vogel <sv@exept.de>
parents: 2976
diff changeset
   747
    "Modified: 24.9.1997 / 09:43:23 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   748
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   749
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   750
!PipeStream class methodsFor:'utilities'!
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   751
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   752
outputFromCommand:aCommand
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   753
    "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
   754
     If the command cannot be executed, return nil.
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   755
     The command's current directory will be the smalltalk current directory."
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   756
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   757
    ^ self outputFromCommand:aCommand inDirectory:nil
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   758
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   759
    "
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   760
     PipeStream outputFromCommand:'ls -l'
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   761
    "
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   762
!
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   763
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   764
outputFromCommand:aCommand errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectoryOrNil
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   765
    "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
   766
     If the command cannot be executed, return nil.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   767
     The current directory of the command will be aDirectoryOrNil 
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   768
     or the smalltalk's current directory (if nil).
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   769
     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
   770
       #discard causes stderr to be discarded (/dev/null),
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   771
       #inline causes it to be merged into the PipeStream and
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   772
       #stderr causes it to be written to smalltalk's own stderr.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   773
       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
   774
       Nil is treated like #stderr"
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   775
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   776
    |p cmdOutput|
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   777
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   778
    p := self readingFrom:aCommand errorDisposition:errorDispositionSymbolOrStream inDirectory:aDirectoryOrNil.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   779
    p isNil ifTrue:[^ nil].
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   780
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   781
    [
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   782
        cmdOutput := p contentsAsString.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   783
    ] ensure:[
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   784
        p close.
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   785
    ].
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   786
    ^ cmdOutput
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   787
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   788
    "
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   789
     PipeStream outputFromCommand:'ls -l' inDirectory:nil
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   790
     PipeStream outputFromCommand:'ls -l' inDirectory:'/'
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   791
     PipeStream outputFromCommand:'ls -l' inDirectory:'/etc'
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   792
    "
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   793
!
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   794
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   795
outputFromCommand:aCommand inDirectory:aDirectoryOrNil
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   796
    "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
   797
     If the command cannot be executed, return nil.
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   798
     The current directory of the command will be aDirectoryOrNil 
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   799
     or the smalltalk's current directory (if nil).
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   800
     Any stderr output will be returned in the returned cmdOutput."
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   801
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   802
    |p cmdOutput|
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   803
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   804
    p := self readingFrom:aCommand inDirectory:aDirectoryOrNil.
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   805
    p isNil ifTrue:[^ nil].
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   806
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   807
    [
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   808
        cmdOutput := p contentsAsString.
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   809
    ] ensure:[
22974
f1df0b1303ab #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22794
diff changeset
   810
        p close.
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   811
    ].
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   812
    ^ cmdOutput
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   813
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   814
    "
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   815
     PipeStream outputFromCommand:'ls -l' inDirectory:nil
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   816
     PipeStream outputFromCommand:'ls -l' inDirectory:'/'
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
   817
     PipeStream outputFromCommand:'ls -l' inDirectory:'/etc'
16579
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   818
    "
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   819
! !
3d51a7434f06 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 16339
diff changeset
   820
99
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   821
!PipeStream methodsFor:'accessing'!
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   822
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   823
commandString
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   824
    "return the command string"
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   825
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   826
    ^ commandString
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   827
!
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   828
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   829
exitStatus
10343
c48f0a54ef69 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9313
diff changeset
   830
    "return the exitStatus"
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   831
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   832
    osProcess isNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   833
        ^ nil.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   834
    ].
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   835
    ^ osProcess exitStatus.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   836
    
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   837
    "Created: 28.12.1995 / 14:54:41 / stefan"
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   838
!
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   839
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   840
pid
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   841
    "return pid"
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   842
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   843
    osProcess isNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   844
        ^ nil.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   845
    ].
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   846
    ^ osProcess pid.
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   847
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   848
    "Created: 28.12.1995 / 14:54:30 / stefan"
99
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   849
! !
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   850
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   851
!PipeStream methodsFor:'closing'!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   852
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   853
abortAndClose
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   854
    "close the Stream and terminate the command"
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   855
20031
8de79de4b866 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   856
    self unregisterForFinalization.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   857
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   858
    "terminate first under windows"
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   859
    OperatingSystem isMSDOSlike ifTrue:[
20031
8de79de4b866 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   860
        self terminatePipeCommand.
21228
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
   861
        self closeFile.
20031
8de79de4b866 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 19860
diff changeset
   862
        ^ self.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   863
    ].
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   864
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   865
    "terminate last under unix"
21228
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
   866
    self closeFile.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   867
    self terminatePipeCommand.
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   868
!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   869
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   870
close
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   871
    "low level close
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   872
     This waits for the command to finish.
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   873
     Use abortAndClose for a fast (nonBlocking) close."
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   874
22696
7b933d672ea3 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22507
diff changeset
   875
    self isOpen ifTrue:[
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   876
        super close.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   877
        "/ wait for the pipe-command to terminate.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   878
        self waitForPipeCommandWithTimeout:nil.
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   879
    ].
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   880
22696
7b933d672ea3 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22507
diff changeset
   881
    "Modified: / 12-09-1998 / 16:51:04 / cg"
7b933d672ea3 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22507
diff changeset
   882
    "Modified: / 23-04-2018 / 18:25:04 / stefan"
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   883
!
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   884
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   885
shutDown
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   886
    <resource: #obsolete>
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   887
    "this is a historic leftover kept for backward compatibility.
20970
54cb5bc5bd05 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20681
diff changeset
   888
     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
   889
     not hard terminate the connection."
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   890
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   891
    self abortAndClose.
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   892
!
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   893
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   894
shutDownOutput
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   895
    "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
   896
8976
2ff451956d48 #shutDownOutput do nothing (ignore errors), if pipe is closed
Stefan Vogel <sv@exept.de>
parents: 8969
diff changeset
   897
    |fd|
2ff451956d48 #shutDownOutput do nothing (ignore errors), if pipe is closed
Stefan Vogel <sv@exept.de>
parents: 8969
diff changeset
   898
2ff451956d48 #shutDownOutput do nothing (ignore errors), if pipe is closed
Stefan Vogel <sv@exept.de>
parents: 8969
diff changeset
   899
    self isOpen ifTrue:[
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   900
	fd := self fileDescriptor.
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   901
	fd notNil ifTrue:[
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   902
	    OperatingSystem shutdownBidirectionalPipeOutput:fd.
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   903
	].
8976
2ff451956d48 #shutDownOutput do nothing (ignore errors), if pipe is closed
Stefan Vogel <sv@exept.de>
parents: 8969
diff changeset
   904
    ].
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   905
! !
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   906
5243
d3b509746522 category change
Claus Gittinger <cg@exept.de>
parents: 5205
diff changeset
   907
!PipeStream methodsFor:'finalization'!
d3b509746522 category change
Claus Gittinger <cg@exept.de>
parents: 5205
diff changeset
   908
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6267
diff changeset
   909
finalize
5243
d3b509746522 category change
Claus Gittinger <cg@exept.de>
parents: 5205
diff changeset
   910
    "redefined to avoid blocking in close."
d3b509746522 category change
Claus Gittinger <cg@exept.de>
parents: 5205
diff changeset
   911
20681
814f81a85289 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20323
diff changeset
   912
    self abortAndClose
18785
5b58b205c252 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18782
diff changeset
   913
! !
5b58b205c252 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18782
diff changeset
   914
5b58b205c252 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18782
diff changeset
   915
!PipeStream methodsFor:'private'!
369
claus
parents: 362
diff changeset
   916
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   917
openPipeFor:aCommandString withMode:rwMode errorDisposition:errorDisposition 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   918
    environment:aShellEnvironmentOrNil inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   919
10408
8027bf22ae31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10363
diff changeset
   920
    "open a pipe to the OS command in commandString;
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   921
     rwMode may be 'r' or 'w' or 'r+'.
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   922
5481
680d6de80808 comment
Claus Gittinger <cg@exept.de>
parents: 5456
diff changeset
   923
     errorDisposition controls where the stdErr output should go,
680d6de80808 comment
Claus Gittinger <cg@exept.de>
parents: 5456
diff changeset
   924
     and may be one of #discard, #inline or #stderr (default).
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   925
       #discard causes stderr to be discarded (/dev/null),
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   926
       #inline causes it to be written to smalltalks own stdout and
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   927
       #stderr causes it to be written to smalltalks own stderr.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   928
       Nil is treated like #stderr."
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   929
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   930
    |pipeArray remotePipeEnd nullOutput errorNumber myPipeEnd result|
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   931
12395
1db7ea277c93 filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 11083
diff changeset
   932
    handle notNil ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   933
        "the pipe was already open ...
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   934
         this should (can) not happen."
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   935
        ^ self errorAlreadyOpen
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   936
    ].
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   937
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   938
    rwMode = #r ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   939
        mode := #readonly. didWrite := false.
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   940
        position := 0.      "only reading - can keep track of position"
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   941
    ] ifFalse:[rwMode = #'r+' ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   942
        mode := #readwrite. didWrite := true.
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   943
    ] ifFalse:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   944
        mode := #writeonly. didWrite := true.
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   945
        position := 0.      "only writing - can keep track of position"
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
   946
    ]].
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   947
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   948
    lastErrorNumber := nil.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   949
    commandString := aCommandString.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   950
    "stdio lib does not work with blocking pipes and interrupts
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   951
     for WIN, Linux, Solaris and probably any other UNIX"
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   952
    buffered := false.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   953
    hitEOF := false.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   954
    binary := false.
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   955
21791
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
   956
    osProcess := OSProcess new
22440
a5f9b3aed756 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21791
diff changeset
   957
                    command:aCommandString directory:aDirectory.
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   958
    aShellEnvironmentOrNil notNil ifTrue:[
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   959
        osProcess environment:aShellEnvironmentOrNil
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
   960
    ].
4616
64dd3a9bebf5 *** empty log message ***
ps
parents: 4526
diff changeset
   961
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   962
    mode == #readwrite ifTrue:[
21211
ed5fd0f7a98b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21210
diff changeset
   963
        pipeArray := self class makeBidirectionalPipe.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   964
        pipeArray isNil ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   965
            lastErrorNumber := errorNumber := OperatingSystem currentErrorNumber.
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   966
            ^ self openError:errorNumber.
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   967
        ].
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   968
        myPipeEnd := pipeArray at:1.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   969
        remotePipeEnd := pipeArray at:2.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   970
        osProcess inStream:remotePipeEnd.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   971
        osProcess outStream:remotePipeEnd.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   972
    ] ifFalse:[
21211
ed5fd0f7a98b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21210
diff changeset
   973
        pipeArray := self class makePipe.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   974
        pipeArray isNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   975
            lastErrorNumber := errorNumber := OperatingSystem currentErrorNumber.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   976
            ^ self openError:errorNumber.
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   977
        ].
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   978
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   979
        mode == #readonly ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   980
            "redirect stdout of subprocess to write to pipe"
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   981
            myPipeEnd := pipeArray at:1.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   982
            remotePipeEnd := pipeArray at:2.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   983
            osProcess outStream:remotePipeEnd.
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   984
        ] ifFalse:[
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   985
            "redirect stdin of subprocess to read from pipe"
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   986
            myPipeEnd := pipeArray at:2.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   987
            remotePipeEnd := pipeArray at:1.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   988
            osProcess inStream:remotePipeEnd.
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   989
        ].
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   990
    ].
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
   991
7079
07625dfffcbf Cleanup filedescriptor closing on #exec:withArguments:....
Stefan Vogel <sv@exept.de>
parents: 7060
diff changeset
   992
    errorDisposition == #discard ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
   993
        nullOutput := Filename nullDevice writeStream.
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   994
        osProcess errorStream:nullOutput.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   995
    ] ifFalse:[(errorDisposition == #inline or:[errorDisposition == #stdout]) ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   996
        osProcess errorStream:osProcess outStream.
21211
ed5fd0f7a98b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21210
diff changeset
   997
    ] ifFalse:[(errorDisposition == #stderr or:[errorDisposition isNil]) ifTrue:[
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   998
        osProcess errorStream:Stderr.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
   999
    ] ifFalse:[errorDisposition isStream ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1000
        osProcess errorStream:errorDisposition.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1001
    ]]]].
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1002
21228
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1003
    mode ~~ #readonly ifTrue:[
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1004
        osProcess terminateActionBlock:[
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1005
                "writing doesn't make sense - there is no reader any longer"
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1006
                mode == #readwrite ifTrue:[
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1007
                    "... but allow to read the rest of the command's output"
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1008
                    self shutDownOutput.
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1009
                ] ifFalse:[mode == #writeonly ifTrue:[
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1010
                    self closeFile.
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1011
                ]].
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1012
           ].
7c2104239a0f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21211
diff changeset
  1013
    ].
8969
978613904d0b For writing Pipestreams: close write side of filedescriptor, when
Stefan Vogel <sv@exept.de>
parents: 8968
diff changeset
  1014
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1015
    result := osProcess startProcess.
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1016
7079
07625dfffcbf Cleanup filedescriptor closing on #exec:withArguments:....
Stefan Vogel <sv@exept.de>
parents: 7060
diff changeset
  1017
    "subprocess has been created.
07625dfffcbf Cleanup filedescriptor closing on #exec:withArguments:....
Stefan Vogel <sv@exept.de>
parents: 7060
diff changeset
  1018
     close unused filedescriptors"
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1019
    remotePipeEnd notNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1020
        remotePipeEnd close.
4202
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
  1021
    ].
b9f85ebd2e38 generalized errorDisposition (for other OS's);
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
  1022
    nullOutput notNil ifTrue:[
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1023
        nullOutput close
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1024
    ].
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1025
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1026
    result ifTrue:[
21791
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1027
        "successful creation of subprocess"
21231
985ae4f2c424 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21228
diff changeset
  1028
        handle := myPipeEnd handle.
985ae4f2c424 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21228
diff changeset
  1029
        handleType := myPipeEnd handleType.
22507
eb40c1d02504 #DOCUMENTATION by mawalch
mawalch
parents: 22440
diff changeset
  1030
        myPipeEnd unregisterForFinalization.    "make sure filedescriptor is not closed by finalizer"
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1031
        myPipeEnd := nil.
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1032
    ] ifFalse:[
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1033
        "the pipe open failed for some reason ...
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1034
         ... this may be either due to an invalid command string,
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1035
         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
  1036
         the unix process)"
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1037
        lastErrorNumber := OperatingSystem lastErrorNumber.
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1038
        myPipeEnd close.
20099
3924a4006e8b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20031
diff changeset
  1039
        ^ self openError:lastErrorNumber.
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1040
    ].
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1041
18782
aa9e2cb1d490 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18638
diff changeset
  1042
    self registerForFinalization.
3296
bd2da537678b md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 3196
diff changeset
  1043
21791
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1044
    "Modified: / 23-04-1996 / 17:05:59 / stefan"
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1045
    "Modified: / 28-01-1998 / 14:47:34 / md"
cec9749a6781 #OTHER by mawalch
mawalch
parents: 21231
diff changeset
  1046
    "Created: / 19-05-1999 / 12:28:54 / cg"
22507
eb40c1d02504 #DOCUMENTATION by mawalch
mawalch
parents: 22440
diff changeset
  1047
    "Modified (comment): / 25-01-2018 / 19:40:27 / mawalch"
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1048
!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1049
22794
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1050
openPipeFor:aCommandString withMode:rwMode errorDisposition:errorDisposition inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1051
    "open a pipe to the OS command in commandString;
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1052
     rwMode may be 'r' or 'w' or 'r+'.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1053
     errorDisposition controls where the stdErr output should go,
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1054
     and may be one of #discard, #inline or #stderr (default).
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1055
     #discard causes stderr to be discarded (/dev/null),
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1056
     #inline causes it to be written to smalltalks own stdout and
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1057
     #stderr causes it to be written to smalltalks own stderr.
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1058
     Nil is treated like #stderr"
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1059
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1060
    ^ self 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1061
        openPipeFor:aCommandString withMode:rwMode errorDisposition:errorDisposition 
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1062
        environment:nil inDirectory:aDirectory
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1063
!
eda5d0a964e5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22696
diff changeset
  1064
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1065
terminatePipeCommand
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1066
    osProcess notNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1067
        osProcess terminateGroup.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1068
    ].
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1069
!
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1070
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1071
waitForPipeCommandWithTimeout:seconds
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1072
    "wait for the pipe command to terminate itself.
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1073
     Return true, if a timeout occurred."
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1074
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1075
    osProcess notNil ifTrue:[
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1076
        ^ osProcess finishSema waitWithTimeout:seconds.
8968
879991b52630 Support for bidirectional PipeStreams
Stefan Vogel <sv@exept.de>
parents: 8520
diff changeset
  1077
    ].
21210
99f6f07d5a33 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20970
diff changeset
  1078
    ^ false
6439
0f841258ec4a Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents: 6267
diff changeset
  1079
! !
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
  1080
22980
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1081
!PipeStream methodsFor:'testing'!
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1082
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1083
isPipeStream
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1084
    ^ true
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1085
! !
8ea9d4f9983a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22975
diff changeset
  1086
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
  1087
!PipeStream class methodsFor:'documentation'!
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1088
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1089
version
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
  1090
    ^ '$Header$'
12712
c1b3b5846541 Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents: 12548
diff changeset
  1091
!
c1b3b5846541 Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents: 12548
diff changeset
  1092
c1b3b5846541 Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents: 12548
diff changeset
  1093
version_CVS
18638
d5624e45f660 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 17460
diff changeset
  1094
    ^ '$Header$'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1095
! !
7027
0efa9d55fa04 Remove unused method var
Stefan Vogel <sv@exept.de>
parents: 6487
diff changeset
  1096
15359
060c677e3e92 class: PipeStream
Claus Gittinger <cg@exept.de>
parents: 14436
diff changeset
  1097
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
  1098
PipeStream initialize!