@staticmethod
def run_file(command, session, settings, timeout=1):
    """Runs a file in the provided session by feeding the interpreter
        one line at a time. At each iteration, run_file checks for a
        continuation or regular prompt and finally closes the expect properly,
        so that the REPLWrapper works properly the next run.
        """
    init, cont = settings.shell['prompt'], settings.shell['continuation']
    results, commands, a, b = [], command.splitlines(), init, cont
    session.sendline(commands[0])
    for line in commands:
        try:
            session.expect(a, timeout=timeout)
        except:
            session.expect(b, timeout=timeout)
            b, a = a, b
        session.sendline(line)
        if a == init:
            output = session.before.splitlines()[1:]
            results.extend(output)
    if a == cont:
        session.sendline('')
        session.expect(init)
        results.append(session.before)
    return '\n'.join(results)
