[m-users.] Capturing process output.

Volker Wysk post at volker-wysk.de
Sun Sep 1 02:38:18 AEST 2024


Hi there

Actually, I've been toying with the idea of writing something like this:

:- pred run_program(
    string::in,                           % Path to executable
    bool::in,                             % Connect stdin?
    bool::in,                             % Connect stdout?
    bool::in,                             % Connect stderr?
    maybe(io.text_output_stream)::out, 	  % Handle to program's stdin
    maybe(io.text_input_stream)::out, 	  % Handle to program's stdout
    maybe(io.text_input_stream)::out, 	  % Handle to program's stderr
    int::out                              % Child process's process id
) is det.

For this to work, a predicate for attaching a stream to an existing file
descriptor would be needed. It doesn't look like this is provided by the
io/io.call_system libraries.

I would be inclined to contribute this to the standard libraries, if that is
welcome. I know that a high code quality would be required.

Cheers
Volker


Am Samstag, dem 31.08.2024 um 16:35 +0200 schrieb Zoltan Somogyi:
> 
> 
> On Sat, 31 Aug 2024 15:30:30 +0100, emacstheviking <objitsu at gmail.com>
> wrote:
> > I have been reading io.system_call and cannot see how to capture the
> > output
> > into a string... was this ever possible?
> 
> Assuming you are talking about io.call_system, the answer is "no".
> 
> > Do I have pipe to a file myself then, then read and process the contents
> > thus generated?
> 
> Yes.
> 
> Zoltan.


More information about the users mailing list