def extract_version(exepath, version_arg, word_index=-<NUM_LIT:1>, version_rank=<NUM_LIT:3>):
if isinstance(version_arg, basestring):<EOL><INDENT>version_arg = [version_arg]<EOL><DEDENT>args = [exepath] + version_arg<EOL>stdout, stderr, returncode = _run_command(args)<EOL>if returncode:<EOL><INDENT>raise RezBindError("<STR_LIT>"<EOL>% (exepath, stderr, returncode))<EOL><DEDENT>stdout = stdout.strip().split('<STR_LIT:\n>')[<NUM_LIT:0>].strip()<EOL>log("<STR_LIT>" % stdout)<EOL>try:<EOL><INDENT>strver = stdout.split()[word_index]<EOL>toks = strver.replace('<STR_LIT:.>', '<STR_LIT:U+0020>').replace('<STR_LIT:->', '<STR_LIT:U+0020>').split()<EOL>strver = '<STR_LIT:.>'.join(toks[:version_rank])<EOL>version = Version(strver)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise RezBindError("<STR_LIT>"<EOL>% (stdout, str(e)))<EOL><DEDENT>log("<STR_LIT>" % str(version))<EOL>return version<EOL>
Run an executable and get the program version.

    Args:
        exepath: Filepath to executable.
        version_arg: Arg to pass to program, eg "-V". Can also be a list.
        word_index: Expect the Nth word of output to be the version.
        version_rank: Cap the version to this many tokens.

    Returns:
        `Version` object.