Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLISP: Returning stdout, stderr, and retcode from a shell command

I am using Common Lisp for some scripting and wanted to have run-program execute shell commands. I have been trying to manipulate the output to get a list in the form (output error returncode) but I can only get either the output or the returncode from run-program.

The arguments here only give you :output (there is no :error):

Is there a way of getting all three? Something like this:

(setf retcode (my-special-cmd "ls" :output stream1 :error stream2))
(print (list stream1 stream2 retcode))
like image 703
AnthonyPhine Avatar asked Dec 21 '25 21:12

AnthonyPhine


1 Answers

run-program returns multiple values. You can handle them as explained in the linked question.

The doc you link to says:

If :STREAM was specified for :INPUT or :OUTPUT, a Lisp STREAM is returned. If :STREAM was specified for both :INPUT and :OUTPUT, three Lisp STREAMs are returned, as for the function EXT:MAKE-PIPE-IO-STREAM.

Thus what you need is either

(EXT:MAKE-PIPE-IO-STREAM "ls")

or

(ext:run-program "ls" :input :stream :output :stream)

Then you will have to read from the streams returned to get the command output. However, in this case you will lose the exit code.

like image 96
sds Avatar answered Dec 24 '25 04:12

sds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!