2

Basically,

(uiop:run-program "echo hello" :output *standard-output*)

outputs hello, while none of

(uiop:launch-program "echo hello" :output *standard-output*)
(uiop:launch-program "echo hello" :output #.*standard-output*)
(uiop:launch-program "echo hello" :output :interactive)

output anything; however, if I do run

(uiop:run-program "echo hello" :output *standard-output*)

after them, I do get hello 4 times indicating echo hello did run. Why is this the case? ((force-output) doesn't change anything either.)

Edit: I am using SBCL with SLIME. And as suggested in the comments, this works as-expected (I get the output) on running it from the terminal.

digikar
  • 576
  • 5
  • 13
  • It seems to happen in Emacs+Slime, calling sbcl from a terminal and executing launch-program with standard-output works over here. – coredump Aug 30 '19 at 06:57
  • Probably a good idea to mention which Lisp you use and how you run it (terminal, slime, something else, ...). When you post a question, it often would be useful to have code and the necessary information, which can be used to reproduce the problem. – Rainer Joswig Aug 30 '19 at 07:03
  • @RainerJoswig, I am using SBCL with SLIME. – digikar Aug 30 '19 at 11:04
  • @coredump, yup, I can confirm that behaviour - it works from the terminal. So, is this a bug? – digikar Aug 30 '19 at 11:05
  • Maybe it's a feature of LAUNCH-PROGRAM? Remember that this is non-trivial: we use SBCL and its output stream is 'connected' to GNU Emacs&SLIME. We then call a shell command which does output, which then gets to -> SBCL -> GNU Emacs&SLIME... – Rainer Joswig Aug 30 '19 at 13:48

1 Answers1

4

When you look at the implementations of run-program and launch-program, you see that the former (in this case…) does a wait-process.

If you issue a uiop:wait-process on the process-info returned by launch-program, your output appears.

I guess that it is a kind of race condition where swank or slime doesn't get to pick up the output before it does something else. I think that this is inherent in the asynchronous behaviour of launch-program.

I think that the clearest way to get the output is to specify :output :stream and then use the stream available from calling process-info-output on the return value of launch-program.

Svante
  • 50,694
  • 11
  • 78
  • 122
  • 1
    My use case turns out to be actually asynchronous, so calling `uiop:wait-process` will not help. I am using `:output :stream` (and reading the output from a separate thread). Thank you for the help! – digikar Sep 01 '19 at 19:41