You can always provide your own stream which is aware of what the current output window is. It could store this in a thread static or just some variable that you update whenever the active window changes. You can set that via ScriptRuntime.IO.OutputStream. You could conceptually do the exact same thing from Python just by setting sys.stdout to a file-like object which knows what the current output window is.
-----Original Message----- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Jeff Slutter Sent: Friday, January 30, 2009 6:02 PM To: Discussion of IronPython Subject: [IronPython] Redirecting stdout/stderr, but with context I have a bit of a problem that I'm not sure how to solve. In my application, I have multiple documents, and each can possibly be performing script operations that print text out via the "print" function. I have one "script output" window, which, only shows the output of whichever is the active document's script (each document has its own ScriptScope). When you switch the active document, the "script output window" refreshes displaying the stdout/stderr text for its script. For each document, I keep a buffer of the text. I redirected stdout/stderr by setting sys.stdout and sys.stderr to an instance of a class I wrote that has the "write" function in it. The problem is, sys.stdout is shared across all of the scopes. So, when I set it for one scope, it changes for all ScriptScopes. I can't figure out a way to pass along the information about which document the stdout output should go to. Is there any way to solve this problem? Or will I have to ban my users from using print and stdout and go with a custom function? Note: Each ScriptScope does have a variable that is the document it belongs to, so I know that information in the script. The problem is, print just goes right to sys.stdout and sys.stdout is shared. Also, keep in mind it is entirely possible for an inactive document to be printing out something. In that case I still need to get the string to be printed, but I'm only storing it at that point (and skipping the output to my textbox). help! Thanks, Jeff _______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com