Hi, I am trying to process a large amount of shell command output that I want to do it line by line. The following code is what I have right now. The while loop will not terminate. I could do that by checking process_running(p). But I think then the last piece of content in the Pipe() needs to be taken care outside the while loop? Are there better way to do the job? Thank you for helping.
p = Pipe()
proc = run(pipeline(cmd, stderr=p), wait=false)
# filter out lines start with Warning
while !eof(p) #does not stop
line = readline(p) |> String
if ~startswith(line, "Warning")
println(line)
end
end
close(p.in)
close(p)
Thank you. Sorry I forgot to type =p. I corrected the post question. Your code works! Could you explain a bit what close(p.in) do? Will that block proc to put content into p?
Thank you very much. Now it is able to evaluate eof(p). Do you happen to know that if the Pipe p reaches eof, does it also mean the proc is ended? So I don’t have to do wait(proc)? (In my case, process_exited(proc) returns true)