R
R
Romses Panagiotis2021-01-10 10:39:00
go
Romses Panagiotis, 2021-01-10 10:39:00

How to read from stdout and, without waiting for the end, redirect the output?

The task is a logical continuation of How to write stdout to a buffer and read from it line by line?

The bottom line is that https://play.golang.org/p/aryjjfUZEmt is waiting for the end of the output. Until this happens, nothing is sent to the broker (in this example, for simplicity, to the screen).
I need not to wait and, as soon as the withdrawal is received, send them to the broker.

I have the main snag with line feeds, because when you receive an array of bytes, write it to the buffer, and another reader can pick it up and analyze the line feeds (using a scanner).

Added:
For an example of the effect, instead cmd := exec.Command("ls", "/etc")of (line 24 from the code above) I took from https://gobyexample.com/tickersand compiled the code for a program that outputs data to stdout not immediately, but gradually using a timer. As a result, it turns out that until the process is completed, in the above example, there will be no sending by rows.

Added:
Updated the code with my attempt.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question