[m-users.] Attaching a stream to a file descriptor

Volker Wysk post at volker-wysk.de
Fri Apr 3 17:40:33 AEDT 2020


Hello

Am Freitag, den 03.04.2020, 16:53 +1100 schrieb Julien Fischer:
> Hi Volker,
> 
> On Thu, 2 Apr 2020, Volker Wysk wrote:
> 
> > Is there a way to make a stream from an existing file descriptor?
> 
> Do you mean make io.{binary,text}_{input,output}_stream out of a file
> descriptor, or make make a file descriptor an instance of the stream
> type classes?

I don't know which one would be better. I've hardly used streams yet.
But I'm thinking of writing a predicate, which runs an external
program, and optionally connects to its stdin, stdout and stderr with
streams. Something like this:

run_program(
  string::in,                       % Program name
  list(string)::in,                 % Arguments
  bool::in,                         % make stdin pipe?
  maybe(binary_output_stream)::out, % stdin pipe if appropriate
  bool::in,                         % make stdout pipe?
  maybe(binary_input_stream)::out,  % stdout pipe if appropriate
  bool::in,                         % make stderr pipe?
  maybe(binary_input_stream)::out)  % stderr pipe if appropriate

The predicate would call pipe(2) in C code, in order to make the
necessary pipes before doing a fork(). From the resulting file
descriptors, streams should be made.

Bye
Volker



More information about the users mailing list