[plt-scheme] hostname

From: Mike (mikee at mikee.ath.cx)
Date: Mon Apr 18 17:42:27 EDT 2005

On Mon, 18 Apr 2005, Eli Barzilay might have said:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> On Apr 18, Hans Oesterholt wrote:
> > Eli Barzilay wrote:
> > 
> > >If you're using Linux, then things are relatively easy:
> > >
> > >  (with-input-from-file "/proc/sys/kernel/hostname" read-line)
> > >  
> > This is somewhat 'proc' fs specific...
> 
> Yes -- I find it useful as something to complement the solution below,
> so you first try and see if that `file' exists, and use its contents
> if so, otherwise use the external process.
> 
> 
> > >If you're using an arbitrary Unix machine, then you should use the
> > >hostname command:
> > >
> > >  (require (lib "process.ss"))
> > >  (let ([s (open-output-string)])
> > >    (parameterize ([current-output-port s]) (system "hostname"))
> > >    (regexp-replace #rx"\n$" (get-output-string s) ""))
> > >  
> > Ok, fair enough, however, what about Windows?
> 
> I don't know how you find the host name on windows, but one of the
> above ways might work.  If there is no file and no executable, then
> you can go with a quick foreign call.
> 
> -- 
>           ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                   http://www.barzilay.org/                 Maze is Life!
> 
> 

On windows what about just reading the environment variable 'COMPUTERNAME'?
I'm still learning mzscheme, and scheme in general. What about:

(define hostname (getenv "COMPUTERNAME"))



Posted on the users mailing list.