use ruby, avoid shelling out. google++
Merge branch 'issue-1154' into 1-x-stable

This is a cherry-pick of an old commit on the 2.x master branch,
and backports a fix to avoid shelling out to get the hostname.

HT: @RunsFor for digging up the solution.

Fixes #1152