Common Lisp: uiop:run-program outputs but uiop:launch-program does not

1.2k views Asked by At

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.

1

There are 1 answers

1
Svante On BEST ANSWER

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.