[mercury-users] Read term from a pipe?

Richard A. O'Keefe ok at atlas.otago.ac.nz
Tue Jun 9 07:11:27 AEST 1998


	The Mercury standard library does not support this,
	mainly because implementing it in a portable fashion is
	a non-trivial exercise.  The obvious way of implementing it
	would be to use the popen() function which is available on
	many Unix systems, but this function is not included
	in the ANSI C standard or even in the POSIX standard.
	
This is somewhat misleading.  popen() is not in the POSIX.1 standard.
I believe there were two reasons for this.
(1) As the rationale section of the standard points out, in "historical"
    (i.e. then existing) implementations, the sequence
	stream = popen("/bin/true");
	(void) system("sleep 100");
	(void) pclose(stream);
    didn't work.  Much to my surprise:  back in 1981 I wondered how
    popen()/pclose() could possibly work given the wait() interface,
    and did figure out a way.  It _could_ have been done right but
    it wasn't.
(2) popen() is defined in terms of the shell.  That's why popen() was
    supposed to be in the POSIX.2 (shell and utilities) standard.  I
    haven't a copy of POSIX.2; I know it extended the C library quite
    a bit with things like glob(), so it would be rather startling if
    popen() was not in fact part of POSIX.2 (which is part of "the"
    POSIX standard).

I would note that there is code out there that could be stolen to make
popen()-like functionality more generally available.  In Tcl, you use
the normal 'open' command, but make the first character of the file
name a vertical bar (a long-standard UNIX convention).  Tcl comes with
_free_ code that could easily and legitimately be swiped by Mercury
that supports 'open {| foo bar} ...' on Unix and all flavours of Windows,
but not MacOS.  I strongly recommend that the Mercury team take a look
at Tcl for multiplatform support.  You don't have to like the language,
just the price ($0.00) for re-using the multiplatform support code.




More information about the users mailing list