One could expect that this works:
s : make_string_output_stream()$
with_stdout(s, system("echo test"))$
print("Output:", get_output_stream_string(s))$
But the output isn't captured, instead it's (for some Lisps) printed to the screen directly.
Tested under CCL, SBCL and GCL.
The comment for
systemin src/macsys.lisp says that some specific Lisps cannot redirect the program output into an existing stream; GCL, ECL, and Clisp are mentioned, however, on investigating, I see that ECL has EXT:RUN-PROGRAM which does allow the output to be captured via the:outputkeyword argument; see: https://ecl.common-lisp.dev/static/manual/Operating-System-Interface.html#Operating-System-Interface I will try to investigate.I didn't look at GCL or Clisp, should do so, but if GCL and Clisp still don't allow for the output to be captured, we'll have to close this ticket as a won't fix.
SBCL also has the functionality via
sb-ext:run-programand the:outputkeyword: https://www.sbcl.org/manual/#Running-external-programsA quick test with cmucl and modifying system to do:
works for the
with_stdoutexample. I don't know what other effects this might have.Originally it said
Tinstead of*standard-output*. The docstring saysTinherits standard-output. Perhaps this is a bug in cmucl's implementation ofrun-program. Or maybe stdout forrun-programisn't*standard-output*.Looks like Clisp does capture the output, and that's already implemented in Maxima
system. I'll update the comment accordingly.That leaves GCL. GCL 2.6.14 documentation for
system::systemseems to show that it can't capture the output. I'll try to look at the source code to verify that and maybe investigate a workaround.This may be of interest, it implements
run-programfor various Lisp implementations: https://gitlab.common-lisp.net/asdf/asdf/blob/master/uiop/run-program.lispOn Wed, Feb 5, 2025 at 9:05 AM David Scherfgen tomasriker@users.sourceforge.net wrote:
asdf isn't supported for all the lisps we support. I'm not keen on
supporting that huge blob of code unless we have asdf as a requirement for
maxima.
Last edit: Robert Dodier 2025-02-06
What I meant is we can see how it can be done (or not) for various Lisps.
I think I see how to get program output to be directed to
*STANDARD-OUTPUT*for the various Lisp implementations presently covered bysystem, except for Allegro and Lispworks; for those I don't have a working installation, but I will consult the documentation and try to guess it.Working on a patch for
system, stay tuned.I've pushed commit 01b2ff8 which, I believe, implements standard output capture for several Lisps on Linux (GCL, ECL, Clisp, CMUCL, Allegro, SBCL, Clozure CL, LispWorks, and ABCL). Haven't tried anything on Windows yet.
Great! Thank you! I can confirm that it works under Windows with SBCL and CCL.
OK, I've pushed patches for various Lisps and tested it on Linux and Windows, and for the combinations I've tried, capturing standard output seems to work as expected. Also made incidental compatibility fixes.
Tried it with Clisp, SBCL, Clozure CL, ABCL, LispWorks, and Allegro on Windows, in addition to stuff on Linux as mentioned above.
git log --author=dodier 01b2ff~1..ade2052will show what I was working on.Closing this ticket as fixed.