[plt-scheme] hostname
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!