Page 1 of 1
Setting Path Variable
Posted: Thu Aug 13, 2009 9:06 pm
by Harnon
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
Posted: Fri Aug 14, 2009 4:49 am
by nuntius
[untested] Try something like (sb-posix:putenv "%PATH%=whatever") or (sb-posix:putenv "PATH=whatever").
Re: Setting Path Variable
Posted: Fri Aug 14, 2009 6:40 am
by Harnon
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
Posted: Fri Aug 14, 2009 8:57 am
by nuntius
Cool. Could you pass this info on to Gary King? Maybe he could add a putenv or (setf getenv) to trivial-shell...
http://common-lisp.net/project/trivial-shell/
Re: Setting Path Variable
Posted: Fri Aug 14, 2009 11:13 am
by Harnon
Done. I don't know if he'll do it though. Heres the code:
Code: Select all
(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))
Re: Setting Path Variable
Posted: Sat Aug 15, 2009 8:01 am
by Harnon
I received a response. Apparently, Osicat
http://common-lisp.net/project/osicat/ already has this functionality. Good to know!
Re: Setting Path Variable
Posted: Mon Sep 14, 2009 11:54 am
by Liam
Also note that CLOCC PORT has this functionality, though it seems that
(setf getenv) is missing for SBCL.
http://clocc.cvs.sourceforge.net/*check ... t/sys.lisp
Liam