Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine the operating system and hostname using common lisp?

To get my .sbclrc file working on the two computers I use, I'd like a way to get the hostname and/or operating system from within sbcl. I know I could set and then look for an environment variable, but is there a more direct approach?

Update

I changed the question to refer to common lisp, since the answer from Ken is not specific to sbcl.

like image 653
Dan Becker Avatar asked Dec 07 '10 01:12

Dan Becker


2 Answers

I'd use the 'environment' functions:

* (machine-instance)
"myhostname"
* (machine-type)
"X86-64"
* (machine-version)
"Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz"
* (software-type)
"Linux"
* (software-version)
"2.6.32-3-amd64"
like image 134
Ken Avatar answered Nov 06 '22 22:11

Ken


* (require :sb-bsd-sockets)
("SB-BSD-SOCKETS" "SB-GROVEL" "ASDF")

* (use-package :sb-bsd-sockets)
T

* (host-ent-name (get-host-by-name "localhost"))
"myhost.mydomain.ext"

* (find :win32 *features*)
:WIN32

* (find :linux *features*)
NIL

EDIT: I like @Ken's solution better. +1.

like image 38
jtdubs Avatar answered Nov 06 '22 22:11

jtdubs