2

I'm trying to call an external shell command in common-lisp, via SBCL's sb-ext:run-program.

Documentation about this run-program command, can be found here: http://sbcl.org/manual/index.html in the section 7.7.3 Running external programs

That page, does not contain examples. I figured out how to use it, by checking this page: stackoverflow examples for sb-ext:run-program

This is what I'm trying to do...

First, I define a variable for a parameter:

(defconstant *a-argument* "-lh")

Then I call a command:

(sb-ext:run-program "C:\\Program Files (x86)\\Gow\\bin\\ls.exe"
                    '(*a-argument*)
                    :output *standard-output*)

It gives me the following error:

debugger invoked on a TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {100299C8F3}>:
  The value
    *A-ARGUMENT*
  is not of type
    SEQUENCE

However, if I call it like this:

(sb-ext:run-program "C:\\Program Files (x86)\\Gow\\bin\\ls.exe"
                    '("-lh")
                    :output *standard-output*)

then it works. The only difference is using "-lh" directly, instead of *a-argument*.

So the question I have is:
What do I need to do, to make the run-program call work, with a variable in the parameter list?

Extra info:

windows32 2.6.1 7601 i686-pc Intel unknown MinGW
SBCL 1.3.8

But I also tested this on FreeBSD 10.1 and there I have the same problem.

Community
  • 1
  • 1
AndyNagels
  • 61
  • 6
  • 1
    `'(*a-argument*)` is a quoted list containing the symbol `*a-argument*`, not the value of the variable by that name (remember that the contents of quoted lists are not evaluated). You need to use `(list *a-argument*)`. – jkiiski Aug 26 '16 at 09:45
  • I tried that, but it seems to evaluate each symbol seperately... giving me the following error: `(sb-ext:run-program "C:\\Program Files (x86)\\Gow\\bin\\ls.exe" '("-lh" (list *a-argument*)) :output *standard-output*) C:\Program Files (x86)\Gow\bin\ls.exe: (LIST: No such file or directory C:\Program Files (x86)\Gow\bin\ls.exe: *A-ARGUMENT*): Invalid argument` – AndyNagels Aug 26 '16 at 10:15
  • Ah, sorry, I see what you mean now... that does seem to work. Thanks @jkiiski. – AndyNagels Aug 26 '16 at 10:19
  • Possible duplicate of [Args for sb-ext:run-program](http://stackoverflow.com/questions/4078448/args-for-sb-extrun-program) – anquegi Aug 26 '16 at 10:26

1 Answers1

4

The answer was given by jkiiski:

I needed to change this call:

(sb-ext:run-program "C:\\Program Files (x86)\\Gow\\bin\\ls.exe"
                    '(*a-argument*)
                    :output *standard-output*)

To this call:

(sb-ext:run-program "C:\\Program Files (x86)\\Gow\\bin\\ls.exe"
                    (list *a-argument*)
                    :output *standard-output*)
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
AndyNagels
  • 61
  • 6