1:- module(hostname, [hostname/1]).

Get hostname

This module provides just one predicate to access the machine hostname. It first looks in the HOSTNAME environment variable. If this is unsuccessful, it call the system hostname command once and keeps the result for reuse.

TODO: what happens if the calling hostname fails? /

   11user:term_expansion(hostname(_),hostname(H)) :-
   12   (  getenv('HOSTNAME',H) -> true
   13   ;  setup_call_cleanup(open(pipe('hostname -s'),read,S),
   14                         read_line_to_codes(S,Codes),
   15                         close(S)), 
   16      atom_codes(H,Codes)
   17   ),
   18   debug(hostname, 'Found hostname: "~w"', [H]).
   19
   20hostname(_)