How can i execute a shell (bash) command within a Common Lisp program and assign the output to a variable?
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Generating powerset in one function, no explicit r
- Invoking Mirth Connect CLI with Powershell script
- Drakma and Dexador both fails at USocket call whil
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- What is the difference between execl and execv?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
You can consider using Trivial-shell (url)
shell-command returns output, so you can assign it to a variable.
In asdf.lisp file you can read:
ASDF provides a
RUN-SHELL-COMMAND
that works with many Common Lisp implementations including ABCL, Allegro CL, CLISP, Clozure CL, ECL, GCL, LispWorks, SBCL, CMU, XCL and SCL.It takes a control string and a list of arguments like
FORMAT
, and synchronously executes the result using a Bourne-compatible shell. Capture output by binding an optional stream.I tried out some answers but it was not straightforward. This is what worked easily:
This is from Edi Weitz's book
Common Lisp Recipes
which belongs to the shelve of any serious Lisp programmer, in my view...In sbcl:
It works fine for me:)
Some CL implementations have built-in functions for this purpose. For example, SBCL has
sb-ext:run-program
, and CCL hasrun-program
.Nowadays I would use
uiop:run-program
, whereuiop
stands for "universal input output" and is a compatibility layer provided by asdf3, formerly known asasdf/driver
. As has been saidasdf:run-shell-command
is obsolete and uiop inherits many features of other libraries such astrivial-shell
.UIOP readme