how to read output after redirect_stdout()

102 views
Skip to first unread message

Yu Gong

unread,
May 31, 2016, 6:23:28 AM5/31/16
to julia-dev
write some code need redirect_stdout, 

rd,wr=redirect_stdout()
print("xx")
println("\n")
readavailable(rd) ---->ok
readavailable(rd)---->blocked here

the question is sometimes I don't know whether there are output in buffer or not, so readavailable will block .

how to avoid blocked when read from pipe when don't know output is null or not ?
 

Miguel Bazdresch

unread,
May 31, 2016, 9:29:50 AM5/31/16
to juli...@googlegroups.com
You can wrap the `readavailable()` call on a task:

    @async while true
        if !isopen(rd)
            break
        end
        data = readavailable(rd)
    end

`data` is a global variable that can be read and written by both the task and the main process.

-- mb

Yu Gong

unread,
Jun 1, 2016, 2:06:31 AM6/1/16
to julia-dev
thanks a lot 

Stefan Karpinski

unread,
Jun 1, 2016, 10:30:54 AM6/1/16
to juli...@googlegroups.com
In the future, this sort of question is better suited for julia-users.
Reply all
Reply to author
Forward
0 new messages