def run_on_text(text, python2_path):
    tees_path = get_config('TEES_PATH')
    if tees_path is None:
        for cpath in tees_candidate_paths:
            cpath = os.path.expanduser(cpath)
            if os.path.isdir(cpath):
                has_expected_files = True
                for f in tees_installation_files:
                    fpath = os.path.join(cpath, f)
                    present = os.path.isfile(fpath)
                    has_expected_files = has_expected_files and present
                has_expected_dirs = True
                for d in tees_installation_dirs:
                    dpath = os.path.join(cpath, d)
                    present = os.path.isdir(dpath)
                    has_expected_dirs = has_expected_dirs and present
                if has_expected_files and has_expected_dirs:
                    tees_path = cpath
                    print('Found TEES installation at ' + cpath)
                    break
    if not os.path.isdir(tees_path):
        raise Exception('Provided TEES directory does not exist.')
    classify_path = 'classify.py'
    tmp_dir = tempfile.mkdtemp(suffix='indra_tees_processor')
    pwd = os.path.abspath(os.getcwd())
    try:
        text_path = os.path.join(tmp_dir, 'text.txt')
        with codecs.open(text_path, 'w', encoding='latin-1', errors='ignore') \
                as f:
            f.write(text)
        output_path = os.path.join(tmp_dir, 'output')
        model_path = os.path.join(tees_path, 'tees_data/models/GE11-test/')
        command = [python2_path, classify_path, '-m', model_path,
                   '-i', text_path,
                   '-o', output_path]
        try:
            pwd = os.path.abspath(os.getcwd())
            os.chdir(tees_path)
            p = subprocess.Popen(command, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE, cwd=tees_path)
            p.wait()
            (so, se) = p.communicate()
            print(so)
            print(se)
            os.chdir(pwd)
        except BaseException as e:
            os.chdir(pwd)
            raise e
    except BaseException as e:
        shutil.rmtree(tmp_dir)
        raise e
    output_tuple = extract_output(tmp_dir)
    shutil.rmtree(tmp_dir)
    return output_tuple