Thank you very much for your advice. Your solution works great.
I’ve simplified the working example to launch the task only for the nescessary time:
function popen3(cmd::Cmd)
pin = Base.Pipe()
out = Base.Pipe()
err = Base.Pipe()
r = spawn(cmd, (pin, out, err))
Base.close_pipe_sync(out.in)
Base.close_pipe_sync(err.in)
Base.close_pipe_sync(pin.out)
Base.start_reading(out.out)
Base.start_reading(err.out)
return (pin.in, out.out, err.out, r)
end
pr = popen3(`c:\\windows\\system32\\ping 127.0.0.1 -t`)
function readresult(pr)
results = [""]
@sync begin
@async begin
#global results
results[1] = ascii(String(readavailable(pr[2])))
end
end
results[1]
end
Calling readresult
gives the right output. Note, the results string must be =[“”]. If it is =“”, the example doesn’t work.
Please could somebody explain me, how to get any results from a task - specifically how the valiables get scoped with the @async block. The manual mentions that all variables are surrounded by a let x=x expressions.
So far my example only works with the string encapsulated ina an array to be a reference.
is there a preferred way to get results from the @async block other than via Arrays?
Thank you
Petr