pasting Steve's code into the windows terminal in 0.3 works for me also. although note that readavailable is also perfectly free to return only one character at time (or any amount, from 1 byte up to and including the amount of data that has been written to it -- it might not even need to return a complete UTF8 characters out of the stream). the only way to be certain you have captured all of the data that has been written to STDOUT is to back out your changes (remove it from the display list, `redirect_stdout(orig_STDOUT)`, and `close(wrstdout)`) then call `readall(rdstdout)`
On Thu, Jul 3, 2014 at 6:48 PM, Laszlo Hars <[email protected]> wrote: > Thanks, Steve. Good to know that something works under MacOS. > Unfortunately, I get nothing to the Windows clipboard with your 2-engine > method, which was the problem that started this thread. (Also, my > application does not need an infinite Julia loop: I can just surround the > code to be executed with output redirection Julia commands - if ever they > would work.) > > > On Thursday, July 3, 2014 2:48:57 PM UTC-6, Steven G. Johnson wrote: >> >> It works for me on MacOS. e.g. putting the code below into a file >> capture.jl, then running >> julia capture.jl >> I can then type e.g. display("foo") and "foo" gets included in the text >> copied to the clipboard. >> >> ##################################################### >> const orig_STDOUT = STDOUT >> rdstdout, wrstdout = redirect_stdout() >> pushdisplay(TextDisplay(STDOUT)) >> >> while true >> try >> result = eval(Base.parse_input_line(STDIN)) >> println("RESULT = ", result) >> catch e >> print("EXCEPTION = ") >> Base.showerror(STDOUT, e) >> end >> s = readavailable(rdstdout) >> clipboard(s) >> print(orig_STDOUT, s) >> end >> >>
