[m-users.] Capturing process output.

Zoltan Somogyi zoltan.somogyi at runbox.com
Sun Sep 1 04:15:20 AEST 2024



On Sat, 31 Aug 2024 18:38:18 +0200, Volker Wysk <post at volker-wysk.de> wrote:
> 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.

There is no such predicate in the Mercury standard library, because
whenever possible, we want library predicates to be platform-agnostic,
running on Windows as well as on Unix-like operating systems,
but file descriptors are a Unix-specific concept. I guess we could add
some abstraction of "an already opened file" that would be a file descriptor
on Unix-like OSs and something else on Windows, but I don't know
what that something else would be. (I know enough about Windows
to know that I don't *want* to know more :-)

I view deciding on such an abstraction, both its meaning and its implementation,
as a necessary first step in implementing the functionality you want,
since it would represent one of its inputs.

Note: the related operations are not in io.call_system.m, but in
io.stream_ops.m. The C, C# and Java foreign_procs there invoke
operations in their respective languages that combine opening a file
with constructing the Mercury representation of a stream of top of
the result of the file open (e.g. on top of a file descriptor on Unix-like OSs).
The logical way to implement the functionality you describe would be
to split each of those operations in two, since you want to use
the second part on its own. So the code you want already (mostly) exists;
it is just currently welded together with code you *don't* want.

> 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.

It would be welcome, but we would need not just a C implementation
that works on Unix/MacOS/Windows (possibly with #ifdefs), but also
C# and Java implementations.

Zoltan.


More information about the users mailing list