Uday Hiwarale
1 min readApr 25, 2020

--

If I am not wrong, you want to get sequential output from a command. You need to use Start and Wait approached discussed in the article. What you can do is use a custom io.Writer object for *Cmd.Stdout. Take help from this article to understand how I/O streams work.

Since you want to read a line at a time, it’s a little complicated. Use Buffer since it can grow in size automatically. It implements io.Writer interface because it implements Write method.

You can use *Buffer.ReadString method which lets your read a string until a character is found which in your case would be a new line or \n. But you would need to read from this buffer every other second or so (in a loop) and write a logic to terminate the reading process.

I am not entirely sure how this will pan out.

--

--

No responses yet