def run_on_text(text, python2_path):
    """Runs TEES on the given text in a temporary directory and returns a
    temporary directory with TEES output.
    
    The caller should delete this directory when done with it. This function
    runs TEES and produces TEES output files but does not process TEES output
    into INDRA statements.

    Parameters
    ----------
    text : str
        Text from which to extract relationships
    python2_path : str
        The path to the python 2 interpreter

    Returns
    -------
    output_dir : str
        Temporary directory with TEES output. The caller should delete this
        directgory when done with it.
    """
    tees_path = get_config('TEES_PATH')

    if tees_path is None:
        # If TEES directory is not specifies, see if any of the candidate paths
        # exist and contain all of the files expected for a TEES installation.
        for cpath in tees_candidate_paths:
            cpath = os.path.expanduser(cpath)
            if os.path.isdir(cpath):
                # Check to see if it has all of the expected files and
                # directories
                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:
                    # We found a directory with all of the files and
                    # directories  we expected in a TEES installation - let's
                    # assume it's a TEES installation
                    tees_path = cpath
                    print('Found TEES installation at ' + cpath)
                    break

    # Make sure the provided TEES directory exists
    if not os.path.isdir(tees_path):
        raise Exception('Provided TEES directory does not exist.')

    # Make sure the classify.py script exists within this directory
    classify_path = 'classify.py'
    # if not os.path.isfile(classify_path):
    #    raise Exception('classify.py does not exist in provided TEES path.')

    # Create a temporary directory to tag the shared-task files
    tmp_dir = tempfile.mkdtemp(suffix='indra_tees_processor')

    pwd = os.path.abspath(os.getcwd())

    try:
        # Write text to a file in the temporary directory
        text_path = os.path.join(tmp_dir, 'text.txt')
        # Had some trouble with non-ascii characters. A possible TODO item in
        # the future is to look into resolving this, for now just ignoring
        # non-latin-1 characters
        with codecs.open(text_path, 'w', encoding='latin-1', errors='ignore') \
                as f:
            f.write(text)

        # Run TEES
        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)  # Change to TEES directory
            # print('cwd is:', os.getcwd())
            # out = subprocess.check_output(command, stderr=subprocess.STDOUT)
            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)  # Change back to previous directory
            # print('cwd is:', os.getcwd())
            # print(out.decode('utf-8'))

        except BaseException as e:
            # If there's an error, print it out and then propagate the
            # exception
            os.chdir(pwd)  # Change back to previous directory
            # print (e.output.decode('utf-8'))
            raise e

    except BaseException as e:
        # If there was an exception, delete the temporary directory and
        # pass on the exception
        shutil.rmtree(tmp_dir)
        raise e
    # Return the temporary directory with the TEES output
    output_tuple = extract_output(tmp_dir)
    shutil.rmtree(tmp_dir)
    return output_tuple
Runs TEES on the given text in a temporary directory and returns a
    temporary directory with TEES output.
    
    The caller should delete this directory when done with it. This function
    runs TEES and produces TEES output files but does not process TEES output
    into INDRA statements.

    Parameters
    ----------
    text : str
        Text from which to extract relationships
    python2_path : str
        The path to the python 2 interpreter

    Returns
    -------
    output_dir : str
        Temporary directory with TEES output. The caller should delete this
        directgory when done with it.