Steve's code works even without "pushdisplay(TextDisplay(STDOUT))", which 
tells us that the problem of not seeing regular Julia console output on 
STDOUT may be because we don't read it properly. We may have to wait, close 
the write pipe, redirect the output back to the original... or something 
else, like printing something. Maybe, the  "print(orig_STDOUT, s)" command 
does the trick?  This should be easy to Julia experts, but drives newbies 
crazy.

On Thursday, July 3, 2014 5:24:39 PM UTC-6, Laszlo Hars wrote:
>
> Oh, I see. It is not a 2-engine solution. It was not clear to me from 
> Steve's post.
> Pasting the code to the Julia console does work, but we need editing of 
> the results. Here are some simple test cases:
> 1+2
> RESULT = 3
>
> print(1+2)
> 3RESULT = nothing
>
> for i = 1:3
> println((i,i^3))
> end
> (1,1)
> (2,8)
> (3,27)
> RESULT = nothing
>
> The clipboard in the end is
> (1,1)(2,8)(3,27)RESULT = nothing
>
>
>
>
>
> On Thursday, July 3, 2014 5:12:32 PM UTC-6, Jameson wrote:
>>
>> 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
>>>>
>>>>  
>>

Reply via email to