This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Setting Path Variable

7 posts · 2059 views

I was just wandering if it is possible to set a temporary path variable in a sbcl command prompt session. In the regular command
prompt (i'm on windows), you can do set %PATH%=whatever , but is this possible once sbcl has actually started? I want to dynamically set the path to folders which contains dlls for my libraries. I want each group of dll to be under a separate folder per foreign library they belong to.
I hope its possible! :)

Re: Setting Path Variable

[untested] Try something like (sb-posix:putenv "%PATH%=whatever") or (sb-posix:putenv "PATH=whatever").

Re: Setting Path Variable

Sweet! it worked.
Getting Environment
SBCL: (sb-posix:getenv "PATH")
CLISP: (ext:getenv "PATH")
ECL: (si:getenv "PATH")

Setting Environment
SBCL: (sb-posix:putenv "PATH=%PATH%;C:/dlls/")
CLISP: (setf (ext:getenv "PATH") "%PATH%;C:/dlls/")
ECL: (si:setenv "PATH" "%PATH%;C:/dlls/")

Re: Setting Path Variable

Done. I don't know if he'll do it though. Heres the code:
(defun envget (var &optional (nullret ""))
  (let ((env #+clisp (ext:getenv (if (equalp var "") " " var))
             #+sbcl (sb-posix:getenv var)
             #+ecl (si:getenv var)
             #+allegro (sys:getenv var)
             #+lispworks (lw:environment-variable var)
             #-(or clisp sbcl ecl allegro lispworks) (error "GETENV is not supported for your implementation")))
    #+clisp (if (equalp env "") nullret env)
    #+(or sbcl allegro lispworks ecl) (if (null env) nullret env)))

(defun envset (var content)
  (let 
    ((it #+clisp (setf (ext:getenv var) content)
         #+sbcl (sb-posix:putenv (concatenate 'string var "=" content))
         #+ecl (si:setenv var content)
         #+allegro (setf (sys:getenv var) content)
         #+lispworks (setf (lw:environment-variable var) content) 
         #-(or clisp sbcl ecl allegro lispworks) 
         (error "SETENV is not supported for your implementation")))
    #+sbcl (if (= it 0) content nil)
    #+(or lispworks clisp allegro ecl) (if it content)))

(defun (setf envget) (var content)
  (envset var content))