the problem is that in both your original code, and your workaround,
you haven't closed the input stream, so you can't know if you've read
everything, so julia is waiting for confirmation before it returns
something. if you call `close(_)` first, then `readbytes(__io)` or
`readall(__io)` will return what you want (`readavailable` does not
have a strong guarantee on how much it returns, so it is only ever
correct to use it in stream parser -- e.g. don't use it)

On Mon, May 26, 2014 at 12:24 PM, Samuel Colvin <[email protected]> wrote:
> Ye I tried that first but it didn't work, nb_available was always zero.
>
> For now I have a hack that works:
>
> while true
> statement, newpos = parse(code, __pos, raise=false)
> statement.head == :error ? break: (__pos = newpos)
> __io, _ = redirect_stdout()
> print("x")
> eval(statement)
> redirect_stdout(STDOUT_OLD)
> result = readavailable(__io)
> close(__io)
> if length(result) > 1
> push!(__output, (__pos, result[2:end]))
> end
> end
>
>
>
> On Monday, 26 May 2014 17:11:13 UTC+1, Keno Fischer wrote:
>>
>> nb_available(rdstd) > 0
>>
>>
>> On Mon, May 26, 2014 at 4:51 PM, Samuel Colvin <[email protected]> wrote:
>>>
>>> readavailable blocks if it's called on pipe with nothing to read. How
>>> does one check if a pipe has something to read before calling readavailable?
>>>
>>> In other words,
>>>
>>> rdstd, wrstd = redirect_stdout()
>>> eval(statement)
>>> if ________
>>> result = readavailable(rdstd)
>>> end
>>> redirect_stdout(STDOUT_OLD)
>>>
>>> Fill in the gap.
>>>
>>> I've tried a whole range of things but nothing is working, surely this
>>> has a simple resolution?
>>
>>
>

Reply via email to