[plt-scheme] hostname

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Apr 18 16:21:59 EDT 2005

On Apr 18, Hans Oesterholt wrote:
> Is there a possibility to retreive the hostname of
> a machine (like 'uname' does) with mzscheme?

If you're using Linux, then things are relatively easy:

  (with-input-from-file "/proc/sys/kernel/hostname" read-line)

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

but that's a rough version -- you'll need to improve it by catching
errors etc.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!



Posted on the users mailing list.