PipeStream.st
author Claus Gittinger <cg@exept.de>
Mon, 22 Sep 1997 21:38:56 +0200
changeset 2969 1fcf6dfb6004
parent 2966 856dfc8a294a
child 2970 f846e7c1962c
permissions -rw-r--r--
VMS pipes in another directory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 99
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
269
93162487a94b *** empty log message ***
claus
parents: 255
diff changeset
    13
NonPositionableExternalStream subclass:#PipeStream
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
    14
	instanceVariableNames:'commandString pid exitStatus exitSema exitAction'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    15
	classVariableNames:'BrokenPipeSignal'
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	category:'Streams-External'
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    18
!
2
claus
parents: 1
diff changeset
    19
217
a0400fdbc933 *** empty log message ***
claus
parents: 180
diff changeset
    20
!PipeStream primitiveDefinitions!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    21
%{
437
claus
parents: 410
diff changeset
    22
793
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    23
#if defined(NT) || defined(WIN32) || defined(MSDOS)
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    24
# undef UNIX_LIKE
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    25
# define MSDOS_LIKE
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    26
#endif
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
    27
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2598
diff changeset
    28
#if defined(__openVMS__)
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2598
diff changeset
    29
# undef __new
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2598
diff changeset
    30
#endif
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2598
diff changeset
    31
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
#include <stdio.h>
437
claus
parents: 410
diff changeset
    33
#define _STDIO_H_INCLUDED_
claus
parents: 410
diff changeset
    34
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
#include <errno.h>
437
claus
parents: 410
diff changeset
    36
#define _ERRNO_H_INCLUDED_
claus
parents: 410
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
#ifndef transputer
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
# include <sys/types.h>
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
# include <sys/stat.h>
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
#endif
230
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    42
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    43
/*
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    44
 * on some systems errno is a macro ... check for it here
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    45
 */
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    46
#ifndef errno
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    47
 extern errno;
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    48
#endif
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
    49
1663
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
    50
#ifdef LINUX
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
    51
# define BUGGY_STDIO_LIB
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
    52
#endif
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
    53
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    54
%}
180
c488255bd0be *** empty log message ***
claus
parents: 159
diff changeset
    55
! !
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    56
325
claus
parents: 308
diff changeset
    57
!PipeStream primitiveFunctions!
claus
parents: 308
diff changeset
    58
%{
claus
parents: 308
diff changeset
    59
claus
parents: 308
diff changeset
    60
/*
2925
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    61
 * no longer needed - popen is useless ...
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    62
 */
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    63
#undef NEED_POPEN_WITH_VFORK
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    64
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    65
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    66
/*
325
claus
parents: 308
diff changeset
    67
 * some systems (i.e. ultrix) use fork;
claus
parents: 308
diff changeset
    68
 * were better off with a popen based on vfork ...
claus
parents: 308
diff changeset
    69
 */
claus
parents: 308
diff changeset
    70
#ifdef NEED_POPEN_WITH_VFORK
claus
parents: 308
diff changeset
    71
claus
parents: 308
diff changeset
    72
static int popen_pid = 0;
claus
parents: 308
diff changeset
    73
claus
parents: 308
diff changeset
    74
FILE *
claus
parents: 308
diff changeset
    75
popen(command, type)
claus
parents: 308
diff changeset
    76
/* const */ char *command;
claus
parents: 308
diff changeset
    77
/* const */ char *type;
claus
parents: 308
diff changeset
    78
{
claus
parents: 308
diff changeset
    79
    int pipes[2];
claus
parents: 308
diff changeset
    80
    int itype = (strcmp(type, "w") == 0 ? 1 : 0);
claus
parents: 308
diff changeset
    81
claus
parents: 308
diff changeset
    82
    if (pipe(pipes) == -1)
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    83
	return NULL;
325
claus
parents: 308
diff changeset
    84
claus
parents: 308
diff changeset
    85
    switch (popen_pid = vfork()) {
claus
parents: 308
diff changeset
    86
    case -1:
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    87
	(void)close(pipes[0]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    88
	(void)close(pipes[1]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    89
	return NULL;
325
claus
parents: 308
diff changeset
    90
claus
parents: 308
diff changeset
    91
    case 0:
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    92
	if (itype) {
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    93
	    dup2(pipes[0], fileno(stdin));
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    94
	    close(pipes[1]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    95
	} else {
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    96
	    dup2(pipes[1], fileno(stdout));
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    97
	    close(pipes[0]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    98
	}
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
    99
	execl("/bin/sh", "/bin/sh", "-c", command, 0);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   100
	fprintf(stderr, "XRN Error: failed the execlp\n");
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   101
	_exit(-1);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   102
	/* NOTREACHED */
325
claus
parents: 308
diff changeset
   103
claus
parents: 308
diff changeset
   104
    default:
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   105
	    if (itype) {
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   106
		close(pipes[0]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   107
		return fdopen(pipes[1], "w");
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   108
	    } else {
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   109
		close(pipes[1]);
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   110
		return fdopen(pipes[0], "r");
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   111
	    }
325
claus
parents: 308
diff changeset
   112
    }
claus
parents: 308
diff changeset
   113
}
claus
parents: 308
diff changeset
   114
claus
parents: 308
diff changeset
   115
int
claus
parents: 308
diff changeset
   116
pclose(str)
claus
parents: 308
diff changeset
   117
FILE *str;
claus
parents: 308
diff changeset
   118
{
claus
parents: 308
diff changeset
   119
    int pd = 0;
claus
parents: 308
diff changeset
   120
    int status;
claus
parents: 308
diff changeset
   121
    int err;
claus
parents: 308
diff changeset
   122
claus
parents: 308
diff changeset
   123
    err = fclose(str);
claus
parents: 308
diff changeset
   124
claus
parents: 308
diff changeset
   125
    do {
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   126
	if ((pd = wait(&status)) == -1)
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   127
	{
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   128
		err = EOF;
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   129
		break;
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   130
	}
325
claus
parents: 308
diff changeset
   131
    } while (pd !=  popen_pid);
claus
parents: 308
diff changeset
   132
claus
parents: 308
diff changeset
   133
    if (err == EOF)
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   134
	return  -1;
325
claus
parents: 308
diff changeset
   135
claus
parents: 308
diff changeset
   136
    if (status)
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   137
	status >>= 8;   /* exit status in high byte */
325
claus
parents: 308
diff changeset
   138
claus
parents: 308
diff changeset
   139
    return status;
claus
parents: 308
diff changeset
   140
}
claus
parents: 308
diff changeset
   141
2925
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   142
#endif /* NEED_POPEN_WITH_VFORK */
325
claus
parents: 308
diff changeset
   143
claus
parents: 308
diff changeset
   144
%}
claus
parents: 308
diff changeset
   145
! !
claus
parents: 308
diff changeset
   146
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   147
!PipeStream class methodsFor:'documentation'!
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   148
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   149
copyright
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   150
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   151
 COPYRIGHT (c) 1989 by Claus Gittinger
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   152
	      All Rights Reserved
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
 This software is furnished under a license and may be used
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   155
 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
   156
 inclusion of the above copyright notice.   This software may not
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   157
 be provided or otherwise made available to, or used by, any
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   158
 other person.  No title to or ownership of the software is
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   159
 hereby transferred.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   160
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   161
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   162
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   163
documentation
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   164
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   165
    Pipestreams allow reading or writing from/to a unix command.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   166
    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
   167
    command, a PipeStream can be created with:
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   168
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   169
	PipeStream readingFrom:'ls -l'
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   170
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   171
    the characters of the commands output can be read using the
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   172
    standard stream messages as next, nextLine etc.
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   173
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   174
    If a writing pipeStream is written to, after the command has finished,
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   175
    UNIX will generate an error-signal (SIGPIPE), which will raise the BrokenPipeSignal. 
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   176
    Thus, to handle this condition correctly, the following code is suggested:
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   177
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   178
	|p|
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   179
	p := PipeStream writingTo:'echo hello'.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   180
	PipeStream brokenPipeSignal handle:[:ex |
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   181
	    'broken pipe' printNewline.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   182
	    p shutDown.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   183
	    ex return
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   184
	] do:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   185
	    p nextPutLine:'oops'.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   186
	   'after write' printNewline.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   187
	    p close.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   188
	   'after close' printNewline
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   189
	]
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   190
1663
dd111ec142da *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1662
diff changeset
   191
    Notice, that iff the Stream is buffered, the Signal may occur some time after
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   192
    the write - or even at close time; to avoid a recursive signal in the exception
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   193
    handler, a #shutDown is useful there; if you use close in the handler, this would
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   194
    try to send any buffered output to the pipe, leading to another brokenPipe exception.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   195
1662
ce26ca3d837c linux stdio does not work with buffered pipes
Claus Gittinger <cg@exept.de>
parents: 1648
diff changeset
   196
    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
   197
    buggy (trying to restart the read ...)
ce26ca3d837c linux stdio does not work with buffered pipes
Claus Gittinger <cg@exept.de>
parents: 1648
diff changeset
   198
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   199
    Currently, no filtering pipeStreams (i.e. both reading AND writing) are provided.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   200
    However, if you look at how things are setup, this can be implemented using the
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   201
    low level primitives #mapePipe and #executeCommand from the OS class protocol.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   202
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   203
    [author:]
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   204
	Claus Gittinger
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   205
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   206
    [see also:]
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   207
	ExternalStream FileStream Socket
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   208
	OperatingSystem
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   209
"
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   210
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   211
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   212
!PipeStream class methodsFor:'initialization'!
2
claus
parents: 1
diff changeset
   213
claus
parents: 1
diff changeset
   214
initialize
claus
parents: 1
diff changeset
   215
    "setup the signal"
claus
parents: 1
diff changeset
   216
57
db9677479d35 *** empty log message ***
claus
parents: 49
diff changeset
   217
    BrokenPipeSignal isNil ifTrue:[
582
21f08116b28d BrokenPipeSignal now a child of WriteErrorSignal
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
	BrokenPipeSignal := WriteErrorSignal newSignalMayProceed:true.
159
514c749165c3 *** empty log message ***
claus
parents: 99
diff changeset
   219
	BrokenPipeSignal nameClass:self message:#brokenPipeSignal.
514c749165c3 *** empty log message ***
claus
parents: 99
diff changeset
   220
	BrokenPipeSignal notifierString:'write on a pipe with no one to read'.
57
db9677479d35 *** empty log message ***
claus
parents: 49
diff changeset
   221
    ]
2
claus
parents: 1
diff changeset
   222
! !
claus
parents: 1
diff changeset
   223
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   224
!PipeStream class methodsFor:'helpers'!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   225
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   226
createCOMFileForVMSCommands:aCollectionOfCommandStrings
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   227
    "since DCL seems to not support multiple commands in one
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   228
     line, create a temporary COM file for them and let DCL
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   229
     execute that one. 
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   230
     A kludge around a poor CLI design."
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   231
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   232
    |tmpComFile s|
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   233
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   234
    tmpComFile := Filename newTemporary withSuffix:'COM'.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   235
    s := tmpComFile writeStream.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   236
    aCollectionOfCommandStrings do:[:aCommand |
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   237
	s nextPutAll:'$'.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   238
	s nextPutAll:aCommand.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   239
	s nextPut:(Character nl).
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   240
    ].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   241
    s close.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   242
    ^ tmpComFile.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   243
!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   244
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   245
createCOMFileForVMSCommand:aCommandString in:aDirectory
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   246
    "since DCL seems to not support multiple commands in one
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   247
     line, create a temporary COM file for a set def, followed
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   248
     by the actual command string.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   249
     A kludge around a poor CLI design."
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   250
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   251
    ^ self
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   252
	createCOMFileForVMSCommands:(Array
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   253
					with:('$set def ' , aDirectory asFilename pathName asFilename osNameForDirectory)
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   254
					with:('$' , aCommandString)).
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   255
! !
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   256
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   257
!PipeStream class methodsFor:'instance creation'!
2
claus
parents: 1
diff changeset
   258
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   259
readingFrom:commandString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   260
    "create and return a new pipeStream which can read from the unix command
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   261
     given by command."
2
claus
parents: 1
diff changeset
   262
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   263
    ^ (self basicNew) readingFrom:commandString
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   264
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   265
    "unix:
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   266
	PipeStream readingFrom:'ls -l'.
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   267
    "
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   268
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   269
    "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   270
	p := PipeStream readingFrom:'ls -l'.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   271
	Transcript showCR:p nextLine.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   272
	p close
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   273
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   274
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   275
    "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   276
	|s|
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   277
	s := PipeStream readingFrom:'sh -c sleep\ 600'.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   278
	(Delay forSeconds:2) wait.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   279
	s shutDown
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   280
    "
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   281
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   282
    "vms:
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   283
	PipeStream readingFrom:'dir'.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   284
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   285
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   286
    "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   287
	|p|
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   288
	p := PipeStream readingFrom:'dir'.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   289
	Transcript showCR:p nextLine.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   290
	p close
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   291
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   292
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   293
    "msdos:
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   294
	PipeStream readingFrom:'dir'.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   295
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   296
    "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   297
	|p|
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   298
	p := PipeStream readingFrom:'dir'.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   299
	Transcript showCR:p nextLine.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   300
	p close
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   301
    "
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   302
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   303
    "Modified: 24.4.1996 / 09:09:25 / stefan"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   304
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   305
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   306
readingFrom:commandString inDirectory:aDirectory
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   307
    "similar to #readingFrom, but changes the directory while
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   308
     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
   309
     executed in another directory, to avoid any OS dependencies
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   310
     in your code."
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   311
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   312
    |cmd tmpComFile pipe|
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   313
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   314
    (OperatingSystem platformName == #vms) ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   315
	tmpComFile := self createCOMFileForVMSCommand:commandString in:aDirectory.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   316
	cmd := '@' , tmpComFile osName.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   317
	pipe := self readingFrom:cmd.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   318
	pipe notNil ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   319
	    pipe exitAction:[tmpComFile delete].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   320
	].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   321
	^ pipe
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   322
    ].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   323
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   324
    "/ unix - prepend a 'cd' to the command
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   325
    cmd := 'cd ' , aDirectory asFilename pathName, '; ' , commandString.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   326
    ^ self readingFrom:cmd
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   327
!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   328
2
claus
parents: 1
diff changeset
   329
writingTo:commandString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   330
    "create and return a new pipeStream which can write to the unix command
a27a279701f8 Initial revision
claus
parents:
diff changeset
   331
     given by command."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   332
2
claus
parents: 1
diff changeset
   333
    ^ (self basicNew) writingTo:commandString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   334
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   335
    "unix:
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   336
	 PipeStream writingTo:'sort'
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   337
    "
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   338
!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   339
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   340
writingTo:commandString inDirectory:aDirectory
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   341
    "similar to #writingTo, but changes the directory while
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   342
     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
   343
     executed in another directory, to avoid any OS dependencies
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   344
     in your code."
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   345
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   346
    |cmd tmpComFile pipe|
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   347
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   348
    (OperatingSystem platformName == #vms) ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   349
	tmpComFile := self createCOMFileForVMSCommand:commandString in:aDirectory.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   350
	cmd := '@' , tmpComFile osName.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   351
	pipe := self writingTo:cmd.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   352
	pipe notNil ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   353
	    pipe exitAction:[tmpComFile delete].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   354
	].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   355
	^ pipe
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   356
    ].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   357
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   358
    "/ unix - prepend a 'cd' to the command
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   359
    cmd := 'cd ' , aDirectory asFilename pathName, '; ' , commandString.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   360
    ^ self writingTo:cmd
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   361
! !
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   362
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   363
!PipeStream class methodsFor:'Signal constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   364
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   365
brokenPipeSignal
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   366
    "return the signal used to handle SIGPIPE unix-signals"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   367
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   368
    ^ BrokenPipeSignal
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   369
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   370
99
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   371
!PipeStream methodsFor:'accessing'!
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   372
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   373
commandString
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   374
    "return the command string"
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   375
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   376
    ^ commandString
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   377
!
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   378
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   379
exitStatus
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   380
    "return exitStatus"
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   381
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   382
    ^ exitStatus
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   383
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   384
    "Created: 28.12.1995 / 14:54:41 / stefan"
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   385
!
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   386
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   387
pid
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   388
    "return pid"
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   389
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   390
    ^ pid
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   391
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   392
    "Created: 28.12.1995 / 14:54:30 / stefan"
99
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   393
! !
afba01fbe15c added access method for commandString
claus
parents: 93
diff changeset
   394
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   395
!PipeStream methodsFor:'instance release'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   396
a27a279701f8 Initial revision
claus
parents:
diff changeset
   397
closeFile
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   398
    "low level close
230
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
   399
     This waits for the command to finish. 
0300c6797890 interrupt & blocking close
claus
parents: 217
diff changeset
   400
     Use shutDown for a fast (nonBlocking) close."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   401
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   402
    filePointer notNil ifTrue:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   403
	super closeFile.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   404
	filePointer := nil.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   405
	pid notNil ifTrue:[
2119
3bb34bc533e6 care for a child to finish right in close
Claus Gittinger <cg@exept.de>
parents: 1984
diff changeset
   406
	    [
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   407
		pid notNil ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   408
		    exitSema wait.
2119
3bb34bc533e6 care for a child to finish right in close
Claus Gittinger <cg@exept.de>
parents: 1984
diff changeset
   409
		]
3bb34bc533e6 care for a child to finish right in close
Claus Gittinger <cg@exept.de>
parents: 1984
diff changeset
   410
	    ] valueUninterruptably
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   411
	].
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   412
    ].
369
claus
parents: 362
diff changeset
   413
!
claus
parents: 362
diff changeset
   414
claus
parents: 362
diff changeset
   415
closeFileDescriptor
claus
parents: 362
diff changeset
   416
    "alternative very low level close 
claus
parents: 362
diff changeset
   417
     This closes the underlying OS-fileDescriptor 
claus
parents: 362
diff changeset
   418
     - and will NOT write any buffered data to the stream.
claus
parents: 362
diff changeset
   419
     You have been warned."
claus
parents: 362
diff changeset
   420
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   421
    |action|
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   422
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   423
%{  
793
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
   424
#if !defined(transputer) && !defined(MSDOS_LIKE)
369
claus
parents: 362
diff changeset
   425
    OBJ fp;
claus
parents: 362
diff changeset
   426
    FILE *f;
claus
parents: 362
diff changeset
   427
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 793
diff changeset
   428
    if ((fp = __INST(filePointer)) != nil) {
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 793
diff changeset
   429
	__INST(filePointer) = nil;
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   430
	f = __FILEVal(fp);
369
claus
parents: 362
diff changeset
   431
	__BEGIN_INTERRUPTABLE__
claus
parents: 362
diff changeset
   432
	close(fileno(f));
claus
parents: 362
diff changeset
   433
	__END_INTERRUPTABLE__
claus
parents: 362
diff changeset
   434
    }
793
3d441d66beeb NT changes
Claus Gittinger <cg@exept.de>
parents: 613
diff changeset
   435
#endif /* not transputer && not MSDOS_LIKE */
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   436
%}.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   437
    exitAction notNil ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   438
	action := exitAction.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   439
	exitAction := nil.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   440
	action value.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   441
    ]
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   442
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   443
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   444
disposed
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   445
    "redefined to avoid blocking in close."
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   446
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   447
    self shutDown
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   448
!
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   449
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   450
shutDown
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   451
    "close the Stream, ignoring any broken-pipe errors.
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   452
     Terminate the command"
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   453
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   454
    BrokenPipeSignal catch:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   455
	|tpid|
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   456
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   457
	Lobby unregister:self.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   458
	self closeFileDescriptor.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   459
	tpid := pid.                    "copy pid to avoid race"
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   460
	tpid notNil ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   461
	    "/
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   462
	    "/ Terminate both the process and group, just in case the
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   463
	    "/ operating system does not support process groups.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   464
	    "/
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   465
	    OperatingSystem terminateProcess:tpid.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   466
	    OperatingSystem terminateProcessGroup:tpid.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   467
	    pid := nil.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   468
	].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   469
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   470
    ]
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   471
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   472
    "Modified: 23.5.1996 / 09:15:41 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   473
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   474
a27a279701f8 Initial revision
claus
parents:
diff changeset
   475
!PipeStream methodsFor:'private'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   476
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   477
exitAction:aBlock
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   478
    "define a block to be evaluated when the pipe is closed.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   479
     This is only used with VMS, to remove any temporary COM file.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   480
     (see readingFrom:inDirectory:)"
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   481
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   482
    exitAction := aBlock
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   483
!
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   484
49
f1c2d75f2eb6 *** empty log message ***
claus
parents: 32
diff changeset
   485
openPipeFor:aCommandString withMode:mode
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   486
    "open a pipe to the unix command in commandString; 
255
2b2c5c0facab *** empty log message ***
claus
parents: 230
diff changeset
   487
     mode may be 'r' or 'w'"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   488
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   489
    |blocked pipeFdArray execFdArray execFd myFd 
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   490
     osType shellPath shellArgs closeFdArray mbx mbxName|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   491
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   492
    filePointer notNil ifTrue:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   493
	"the pipe was already open ...
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   494
	 this should (can) not happen."
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   495
	^ self errorOpen
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   496
    ].
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   497
    lastErrorNumber := nil.
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   498
    exitStatus := nil.
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   499
    exitSema := Semaphore new name:'pipe exitSema'.
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   500
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   501
    osType := OperatingSystem platformName.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   502
    osType == #vms ifTrue:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   503
	mbx := OperatingSystem createMailBox.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   504
	mbx isNil ifTrue:[
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   505
	    lastErrorNumber := OperatingSystem currentErrorNumber.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   506
	    ^ self openError
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   507
	].
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   508
	mbxName := OperatingSystem mailBoxNameOf:mbx.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   509
'mailBox is ' print. mbx print. ' name is ' print. mbxName printCR.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   510
	shellPath := ''.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   511
	shellArgs := aCommandString.
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   512
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   513
	mode = 'r' ifTrue:[
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   514
	    execFdArray := Array with:0 with:mbx with:2.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   515
	] ifFalse:[
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   516
	    execFdArray := Array with:mbx with:1 with:2.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   517
	].
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   518
	closeFdArray := nil.
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   519
    ] ifFalse:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   520
	pipeFdArray := OperatingSystem makePipe.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   521
	pipeFdArray isNil ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   522
	    lastErrorNumber := OperatingSystem currentErrorNumber.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   523
	    ^ self openError
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   524
	].
255
2b2c5c0facab *** empty log message ***
claus
parents: 230
diff changeset
   525
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   526
	osType == #unix ifTrue:[
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   527
	    shellPath := '/bin/sh'.
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   528
	    shellArgs := Array with:'sh' with:'-c' with:aCommandString.
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   529
	] ifFalse:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   530
	    osType == #win32 ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   531
		shellPath := 'C:\WINNT\System32\cmd /c'.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   532
		shellArgs := aCommandString.
2925
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   533
	    ] ifFalse:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   534
		OperatingSystem closeFd:execFd; closeFd:myFd.
2925
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   535
		"/
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   536
		"/ dont know how to do it ...
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   537
		"/
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   538
		^ self openError
2925
1a64228425ca *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   539
	    ]
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   540
	].
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   541
	mode = 'r' ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   542
	    execFd := pipeFdArray at:2.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   543
	    execFdArray := Array with:0 with:execFd with:2.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   544
	    myFd := pipeFdArray at:1.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   545
	] ifFalse:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   546
	    execFd := pipeFdArray at:1.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   547
	    execFdArray := Array with:execFd with:1 with:2.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   548
	    myFd := pipeFdArray at:2.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   549
	].
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   550
	closeFdArray := Array with:myFd.
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   551
    ].
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   552
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   553
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   554
    "/ must block here, to avoid races due to early finishing
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   555
    "/ subprocesses ...
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   556
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   557
    blocked := OperatingSystem blockInterrupts.
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   558
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   559
    pid := Processor 
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   560
	       monitor:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   561
		  OperatingSystem 
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   562
		      exec:shellPath
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   563
		      withArguments:shellArgs
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   564
		      fileDescriptors:execFdArray
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   565
		      closeDescriptors:closeFdArray
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   566
		      fork:true
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   567
		      newPgrp:true.
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   568
	       ]
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   569
	       action:[:status |
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   570
		  status stillAlive ifFalse:[
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   571
		      exitStatus := status.
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   572
		      pid := nil.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   573
		      exitSema signal.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   574
		  ].
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   575
	       ].
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   576
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   577
    (osType ~~ #vms) ifTrue:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   578
	OperatingSystem closeFd:execFd.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   579
    ].
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   580
2498
eb0bad72f05e Fixe race when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2266
diff changeset
   581
    pid notNil ifTrue:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   582
	(osType == #win32) ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   583
	    self setFileHandle:myFd mode:mode
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   584
	] ifFalse:[
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   585
	    (osType == #vms) ifTrue:[
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   586
		"/
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   587
		"/ reopen the mailbox as a file ...
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   588
		"/
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   589
		mbxName := OperatingSystem mailBoxNameOf:mbx.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   590
		mbxName notNil ifTrue:[
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   591
		    super open:mbxName withMode:mode
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   592
		].
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   593
	    ] ifFalse:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   594
		self setFileDescriptor:myFd mode:mode.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   595
	    ]
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   596
	]
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   597
    ] ifFalse:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   598
	lastErrorNumber := OperatingSystem currentErrorNumber.
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   599
	osType ~~ #vms ifTrue:[
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   600
	    OperatingSystem closeFd:myFd.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   601
	] ifFalse:[
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   602
	    OperatingSystem destroyMailBox:mbx
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   603
	].
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   604
    ].
2598
519202e09350 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2597
diff changeset
   605
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   606
    blocked ifFalse:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   607
	OperatingSystem unblockInterrupts
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   608
    ].
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   609
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   610
    lastErrorNumber notNil ifTrue:[
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   611
	"
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   612
	 the pipe open failed for some reason ...
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   613
	 ... this may be either due to an invalid command string,
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   614
	 or due to the system running out of memory (when forking
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   615
	 the unix process)
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   616
	"
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   617
	^ self openError
255
2b2c5c0facab *** empty log message ***
claus
parents: 230
diff changeset
   618
    ].
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   619
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   620
    commandString := aCommandString.
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   621
%{
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   622
    /* LINUX stdio is corrupt here ... */
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   623
#ifdef BUGGY_STDIO_LIB
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   624
    __INST(buffered) = false;
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   625
#else
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   626
    __INST(buffered) = true;
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   627
#endif
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   628
%}.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   629
    position := 1.
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   630
    hitEOF := false.
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   631
    binary := false.
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2953
diff changeset
   632
    Lobby register:self.
1648
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   633
faa891d2c1b0 Use OperatingSystem executeCommand:... instead of popen().
Stefan Vogel <sv@exept.de>
parents: 1295
diff changeset
   634
    "Modified: 23.4.1996 / 17:05:59 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   635
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   636
a27a279701f8 Initial revision
claus
parents:
diff changeset
   637
readingFrom:command
a27a279701f8 Initial revision
claus
parents:
diff changeset
   638
    "setup the receiver to read from command"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   639
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   640
    mode := #readonly. didWrite := false.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   641
    ^ self openPipeFor:command withMode:'r'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   642
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   643
a27a279701f8 Initial revision
claus
parents:
diff changeset
   644
writingTo:command
a27a279701f8 Initial revision
claus
parents:
diff changeset
   645
    "setup the receiver to write to command"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   646
326
d2902942491d *** empty log message ***
claus
parents: 325
diff changeset
   647
    mode := #writeonly. didWrite := true.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   648
    ^ self openPipeFor:command withMode:'w'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   649
! !
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   650
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2121
diff changeset
   651
!PipeStream class methodsFor:'documentation'!
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   652
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   653
version
2969
1fcf6dfb6004 VMS pipes in another directory
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   654
    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.59 1997-09-22 19:38:56 cg Exp $'
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   655
! !
613
0af19c3594fc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
   656
PipeStream initialize!