def run_cmd(dir, args, with_retcode=False, with_stderr=False, raise_error=False, input=None, env={}, run_bg=False, setup_askpass=False):
    # Check args
    if type(args) in [str, unicode]:
        args = [args]
    args = [str(a) for a in args]

    # Check directory
    if not os.path.isdir(dir):
        raise GitError, 'Directory not exists: ' + dir

    try:
        os.chdir(dir)
    except __HOLE__, msg:
        raise GitError, msg

    # Run command
    if type(args) != list:
        args = [args]

    # Setup environment
    git_env = dict(os.environ)
    if setup_askpass and 'SSH_ASKPASS' not in git_env:
        git_env['SSH_ASKPASS'] = '%s-askpass' % os.path.realpath(os.path.abspath(sys.argv[0]))

    git_env.update(env)
    
    preexec_fn = os.setsid if setup_askpass else None

    p = Popen([git_binary()] + args, stdout=subprocess.PIPE,
              stderr=subprocess.PIPE, stdin=subprocess.PIPE,
              env=git_env, shell=False, preexec_fn=preexec_fn)
    if run_bg:
        return p

    if input == None:
        stdout,stderr = p.communicate('')
    else:
        stdout,stderr = p.communicate(utf8_str(input))
    
    # Return command output in a form given by arguments
    ret = []

    if p.returncode != 0 and raise_error:
        raise GitError, 'git returned with the following error:\n%s' % stderr

    if with_retcode:
        ret.append(p.returncode)

    ret.append(stdout)

    if with_stderr:
        ret.append(stderr)

    if len(ret) == 1:
        return ret[0]
    else:
        return tuple(ret)
dataset/ETHPy150Open gyim/stupidgit/stupidgit_gui/git.py/run_cmd