Fixing subprocess.check_output for old python

The `check_output` function was introduced in Python 2.7, so in order
to keep this running on older versions, the code from the 2.7
release is patched in here.