3

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))
sds
  • 58,617
  • 29
  • 161
  • 278
  • Possible duplicate of [values function in Common Lisp](http://stackoverflow.com/questions/22795608/values-function-in-common-lisp) – sds Oct 13 '15 at 22:45

1 Answers1

2

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.

Community
  • 1
  • 1
sds
  • 58,617
  • 29
  • 161
  • 278