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.
List Files
First of all, if all you want is to list files, you can use the standard
directory
or CLISP-specificext:dir
.Globbing
Second, the
"*"
globbing is expanded by shell, not individual commands, so you need to useext:run-shell-command
instead ofext:run-program
:Summary
The manual assumes a certain level of familiarity with the way modern OSes work in this respect. The other excellent answer addresses those issues in detail; briefly:
run-program
executes another program using the standardfork
/exec
paradigmrun-shell-command
goes through shell, so you can use globbing and things like loopsshell
is mostly for interactive useMore examples
You can find more example of
run-program
in the CLISP test suite.If you want to read from a compressed file, you can do this:
Actually, you can use CLISP as your shell!