A more portable way would be to use pathnames and dynamically binding *default-pathname-defaults*
, which would effectively set your current working directory. I had the same problem today. Here is a working adaptation of dot->png
from Land of Lisp text by Conrad Barski, that specifies the current working directory:
(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*)))
Posted in the hope that this could be useful to someone in a similar situation & running across this thread.