Move subprocess with error logging into a helper function and actually include the output in the error log