Executes
Command
, which may contain arguments, setting it up such that
the executed command's stdin comes from the returned stream if
Mode
is
Out_Stream
, or the command's stdout can be read from that stream
if
Mode
is
In_Stream
. Note that "in" and "out" are from the caller's
perspective.
If Close = True
, the stream is closed automatically when
the stream object disappears. Note that this may involve waiting until
the external command terminates. Out_Stream
s always are closed
automatically.
Raises Name_Error
if the Command
cannot be executed, or Use_Error
if the stream is already open.
Note that an output filter is created using a stream of mode
Out_Stream
. The external process will share its stdout with the
calling application, so you should carefully flush your stdout before
opening such a pipe, otherwise, output may become garbled and mixed up.
The same applies to an input filter: it shares its stdin with
the calling application! Unfortunately, one cannot flush an input stream
(that would be a meaningless operation anyway), so be careful!
One way to avoid such problems is using the Std_In
parameter. If it
is not the empty string, the command's stdin is redirected to come
from the given filename (which had better be valid). In other words,
the command actually executed is Command & " <" & Std_In
.
If this feature is used, the caller is responsible for removing the
file, if that is desired.