[go: up one dir, main page]

Menu

#4471 with_stdout doesn't capture output of command executed via system

None
closed
nobody
5
2025-02-24
2025-01-28
No

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.

Discussion

  • Robert Dodier

    Robert Dodier - 2025-02-05

    The comment for system in 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 :output keyword 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.

     
    • David Scherfgen

      David Scherfgen - 2025-02-05

      SBCL also has the functionality via sb-ext:run-program and the :output keyword: https://www.sbcl.org/manual/#Running-external-programs

       
      • Raymond Toy

        Raymond Toy - 2025-02-05

        A quick test with cmucl and modifying system to do:

        (ext:run-program shell (list shell-opt (apply '$sconcat args)) :output (or s *standard-output*))
        

        works for the with_stdout example. I don't know what other effects this might have.

        Originally it said T instead of *standard-output*. The docstring says T inherits standard-output. Perhaps this is a bug in cmucl's implementation of run-program. Or maybe stdout for run-program isn't *standard-output*.

         
  • Robert Dodier

    Robert Dodier - 2025-02-05

    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::system seems 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.

     
  • Robert Dodier

    Robert Dodier - 2025-02-08

    I think I see how to get program output to be directed to *STANDARD-OUTPUT* for the various Lisp implementations presently covered by system, 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.

     
  • Robert Dodier

    Robert Dodier - 2025-02-14

    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.

     
    👍
    1
    • David Scherfgen

      David Scherfgen - 2025-02-17

      Great! Thank you! I can confirm that it works under Windows with SBCL and CCL.

       
  • Robert Dodier

    Robert Dodier - 2025-02-24

    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..ade2052 will show what I was working on.

    Closing this ticket as fixed.

     
  • Robert Dodier

    Robert Dodier - 2025-02-24
    • status: open --> closed
     

Log in to post a comment.