in reply to not getting hostname correctly on UNIX

You can also try getting the hostname without calling an external program:

perl -MPOSIX -le 'print((uname)[1])'