一种更便携的方法是使用路径名和动态绑定*default-pathname-defaults*
,这将有效地设置您当前的工作目录。我今天遇到了同样的问题。以下是 Conrad Barski 对 Land of Lisp 文本的工作改编dot->png
,它指定了当前工作目录:
(defun dot->png (filespec thunk)
"Save DOT information generated by a thunk on a *STANDARD-OUTPUT* to a FILESPEC file. Then use FILESPEC to create a corresponding png picture of a graph."
;; dump DOT file first
(let ((*default-pathname-defaults*
(make-pathname :directory (pathname-directory (pathname filespec)))))
;; (format t "pwd (curr working dir): ~A~%" *default-pathname-defaults*)
(with-open-file (*standard-output*
filespec
:direction :output
:if-exists :supersede)
(funcall thunk))
#+sbcl
(sb-ext:run-program "/bin/sh"
(list "-c" (concatenate 'string "dot -Tpng -O " filespec))
:input nil
:output *standard-output*)
#+clozure
(ccl:run-program "/bin/sh"
(list "-c" (concatenate 'string "dot -Tpng -O" filespec))
:input nil
:output *standard-output*)))
发布希望这对处于类似情况并在此线程中运行的人有用。