[Openmcl-devel] Pre-wheel-reinvention query: anyone written an FFI hookup to popen?

Gary Byers gb at clozure.com
Thu Jun 4 16:29:48 PDT 2009


(defun popen (command mode)
    "command should be a string, passed to \"sh -c\".  mode indicates
     whether the returned stdio stream will be open for reading (\"r\"),
     writing (\"w\"), or both (\"r+\").
     Return value is a pointer to an stdio stream; if the pointer's NULL,
     an error occurred."
    (with-cstrs ((ccommand command)
                 (cmode mode))
      (let* ((stdio-stream (#_popen ccommand cmode)))
        (if (%null-ptr-p stdio-stream)
          (ccl::%errno-disp (ccl::%get-errno))
          stdio-stream))))

The number of things that you can usefully do with a C "FILE *" pointer
in CCL is pretty limited.  You could pass that pointer to foreign code
that wants a "FILE *", or if you were really trying to avoid use of
CCL:RUN-PROGRAM for some reason you could write a Gray Stream wrapper
around stdio streams, but it seems like it'd be simpler to just use
RUN-PROGRAM.

On Thu, 4 Jun 2009, Ron Garret wrote:

> Subject line says it all.  I need to call popen.  I'm sure it's not
> hard, which is why I thought I'd ask if it's already been done before
> diving in.
>
> Thanks,
> rg
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list