'This is partially borrowed from subprocess.Popen.'

def _handle_exitstatus(self, sts):

    if os.WIFSIGNALED(sts):
        self.returncode = (- os.WTERMSIG(sts))
    elif os.WIFEXITED(sts):
        self.returncode = os.WEXITSTATUS(sts)
    else:
        raise RuntimeError('Unknown    child    exit    status!')
    if (self.returncode != 0):
        print ('subcommand    failed    pid    %d' % self.pid)
        print ('%s' % (self.func,))
        print ('rc=%d' % self.returncode)
        print
        if self.debug:
            stderr_file = os.path.join(self.debug, 'autoserv.stderr')
            if os.path.exists(stderr_file):
                for line in open(stderr_file).readlines():
                    print line,
        print '\n--------------------------------------------\n'
        raise error.AutoservSubcommandError(self.func, self.returncode)
