I am trying to figure out a way to redirect output from a script that I'm writing that runs the interactive console.
I need to be able to:
capture the output in a string, and then check it, or print it out.
Is this doable? Should I be using a different python module?
I tried this with the subprocess
module, but ran into a problem where I could only do 1 read at the end of the process. That won't work, I need to read multiple times from stdout. This is what I have so far:
import code
console = code.InteractiveConsole()
console.push('from sim import newsteam\n')
console.push('assembler = newsteam()\n')
console.push('assembler.__init__()\n')
line = console.push('assembler.reportr()\n')
#I need to be able to interact with this output
line1 = console.push('assembler.reportpc()\n')
line2 = console.push('assembler.reportm()\n')
print("this is the result: " + line + line1 + line2)