Setting Path Variable

Discussion of Common Lisp
Post Reply
Harnon
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Setting Path Variable

Post by Harnon » Thu Aug 13, 2009 9:06 pm

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! :)

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Setting Path Variable

Post by nuntius » Fri Aug 14, 2009 4:49 am

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

Harnon
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Setting Path Variable

Post by Harnon » Fri Aug 14, 2009 6:40 am

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/")

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Setting Path Variable

Post by nuntius » Fri Aug 14, 2009 8:57 am

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/

Harnon
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Setting Path Variable

Post by Harnon » Fri Aug 14, 2009 11:13 am

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))

Harnon
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Setting Path Variable

Post by Harnon » Sat Aug 15, 2009 8:01 am

I received a response. Apparently, Osicat http://common-lisp.net/project/osicat/ already has this functionality. Good to know!

Liam
Posts: 2
Joined: Mon Mar 30, 2009 9:35 am

Re: Setting Path Variable

Post by Liam » Mon Sep 14, 2009 11:54 am

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

Post Reply