def run_source(self,source,interact=False,get_output=False):
<EOL>if isinstance(source, str):<EOL><INDENT>source = source.splitlines(True)<EOL><DEDENT>if self.echo:<EOL><INDENT>linesep  = os.linesep<EOL>stdwrite = self.out.write<EOL>write    = lambda s: stdwrite(s.replace('<STR_LIT:\r\n>',linesep))<EOL><DEDENT>else:<EOL><INDENT>write = lambda s: None<EOL><DEDENT>c = self.child<EOL>prompts = c.compile_pattern_list(self.prompts)<EOL>prompt_idx = c.expect_list(prompts)<EOL>end_normal = True<EOL>if get_output:<EOL><INDENT>output = []<EOL>store_output = output.append<EOL><DEDENT>for cmd in source:<EOL><INDENT>if prompt_idx==<NUM_LIT:0> and(cmd.isspace() or cmd.lstrip().startswith('<STR_LIT:#>')):<EOL><INDENT>write(cmd)<EOL>continue<EOL><DEDENT>write(c.after)<EOL>c.send(cmd)<EOL>try:<EOL><INDENT>prompt_idx = c.expect_list(prompts)<EOL><DEDENT>except pexpect.EOF:<EOL><INDENT>write(c.before)<EOL>end_normal = False<EOL>break<EOL><DEDENT>write(c.before)<EOL>if get_output:<EOL><INDENT>store_output(c.before[len(cmd+'<STR_LIT:\n>'):])<EOL><DEDENT><DEDENT>self.out.flush()<EOL>if end_normal:<EOL><INDENT>if interact:<EOL><INDENT>c.send('<STR_LIT:\n>')<EOL>print('<STR_LIT>', end='<STR_LIT:U+0020>')<EOL>try:<EOL><INDENT>c.interact()<EOL><DEDENT>except OSError:<EOL><INDENT>write('<STR_LIT>')<EOL>self.out.flush()<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if interact:<EOL><INDENT>e="<STR_LIT>"<EOL>print(e, file=sys.stderr)<EOL><DEDENT><DEDENT>if c.isalive():<EOL><INDENT>c.send('<STR_LIT:\n>')<EOL><DEDENT>if get_output:<EOL><INDENT>return '<STR_LIT>'.join(output)<EOL><DEDENT>
Run the given source code interactively.

        Inputs:

          - source: a string of code to be executed, or an open file object we
          can iterate over.

        Optional inputs:

          - interact(False): if true, start to interact with the running
          program at the end of the script.  Otherwise, just exit.

          - get_output(False): if true, capture the output of the child process
          (filtering the input commands out) and return it as a string.

        Returns:
          A string containing the process output, but only if requested.