No I'm that doesn't work either. I've tried every possible combination and only the hack seems to work.
I'm on mac, versioninfo: julia> versioninfo() Julia Version 0.3.0-prerelease+3121 Commit e1468d5 (2014-05-19 22:16 UTC) Platform Info: System: Darwin (x86_64-apple-darwin13.2.0) CPU: Intel(R) Core(TM) i7 CPU M 640 @ 2.80GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY) LAPACK: libopenblas LIBM: libopenlibm On Monday, 26 May 2014 18:08:27 UTC+1, Jameson wrote: > > 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]<javascript:>> > 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? > >> > >> > > >
