I am having trouble using run-program with arguments. The documentation at http://www.clisp.org/impnotes/shell.html is very incomplete for a newbie like me, and I would need to see some examples.
In particular, how can I get the directory list of files with "txt" extension?
This works:
(ext:run-program "ls" ) ; I am running on Mac OS X
but if I add arguments, it doesn't work. I have tried:
(ext:run-program "ls" :arguments "*.txt")
(ext:run-program "ls" :arguments '(*.txt))
(ext:run-program "ls *.txt)
Can anyone tell me the right syntax and, hopefully, provide some more examples of run-program?
Note that the above is just an example. What I want is to be able to use run-command, not to list the directory, which I can do with list-directory.
Thanks for any help.
Try something like
I am using
stat, notlsin this example.What you might want is globbing (read glob(7)). You should do it yourself in Lisp, or else run
/bin/sh -c; in other words it is up to you to build the expanded list passed after:arguments. (You can't pass*.txtas a single argument, it would have the same effect as a quoted shell argument like inls '*.txt'shell command)This is not CLISP specific.
ext:run-programis probably forking then calling (in the child) execve(2) so you have to do the globbing yourself.Maybe you want the CLISP equivalent of glob(3) or fnmatch(3). I don't know enough CLISP if it has them or not.
Read Advanced Linux Programming to get a more clear picture of this. On POSIX systems the invoking process (often your shell when typing a command, or your Common Lisp program if using
ext:run-program....) has to expand and build the argument list. The point is that when you runls *.txtit is your shell (not thelsprocess) which is expanding*.txt, solsis getting an expanded argument list like e.g.a.txt foo.txt bar.txt; so you need to do the same in your Lisp code.