Search code examples
common-lispsbclcclecl

Can I specify directory for shell command?


I use the following function to run shell commands:

(defun sh (cmd)
  #+clisp (shell cmd)
  #+ecl (si:system cmd)
  #+sbcl (sb-ext:run-program "/bin/sh" (list "-c" cmd) :input nil :output*standard-output*)
  #+clozure (ccl:run-program "/bin/sh" (list "-c" cmd) :input nil :output*standard-output*)))

For example, How to specify the current directory for command python -m CGIHTTPServer ?

Sincerely!


Solution

  • In ECL you can use EXT:CHDIR before SYSTEM, which changes both default-pathname-defaults and the value of the current directory, as understood by the operating system and C library.

    BTW: If possible use (EXT:RUN-PROGRAM "command" list-of-args) instead