I'm using emacs 25.2.1 on Windows with spacemacs (0.200.9). I also start emacs as a service using emacsclientw.exe --daemon. I'm attempting to get the current host name using (system-name) as follows:

(defconst jp-hostname
  (car (split-string (system-name) "\\." t)))

Unfortunately, when I do this, the jp-hostname variable contains the NETBIOS name instead of the hostname. For example, my laptop's name is "jaundiced-outlook", but jp-hostname is set to "JAUNDICED-OUTLO".

Calling (system-name) after emacs is up and running returns what I would expect: "jaundiced-outlook".

By waiting until emacs is finished loading and executing the above code using eval-region, jp-hostname gets set correctly to "jaundiced-outlook".

Is there a reason for this behavior? Is there a way to get around this kind of thing?

  • How are you evaluating that using Emacs in the case where it returns the wrong value, if you are not doing that "after emacs is started"? It's not clear (to me) just what you are doing. You might want to provide a recipe, starting with no init file.
    – Drew
    Jul 4 '17 at 3:45
  • When I start emacs using -q, (message (system-name)) displays the NETBIOS name in the messages buffer. The "after emacs is started" would occur if I select the code in question and run eval-region. I'll clean up the question appropriately.
    – Jeremiah Peschka
    Jul 4 '17 at 3:54

Eventually, the only reliable way I found to resolve the issue (how do I get the host name, not the NETBIOS name) was to shell out to the hostname command:

(defconst jp-hostname
  ;; This should use the following line, but it doesn't work for some reason
  ;; So, instead, we resort to shelling out
  ;; (car (split-string (system-name) "\\." t))
  (string-trim (with-output-to-string
    (call-process "hostname" nil standard-output nil))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.