File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -334,6 +334,8 @@ func (c *Cmd) run(in io.Reader) {
334334 // who's waiting for us to close them.
335335 if c .stdoutStream != nil {
336336 defer func () {
337+ c .stdoutStream .Flush ()
338+ c .stderrStream .Flush ()
337339 // exec.Cmd.Wait has already waited for all output:
338340 // Otherwise, during the execution of the command a separate goroutine
339341 // reads from the process over a pipe and delivers that data to the
@@ -643,3 +645,11 @@ func (rw *OutputStream) SetLineBufferSize(n int) {
643645 rw .bufSize = n
644646 rw .buf = make ([]byte , rw .bufSize )
645647}
648+
649+ // Flush empties the buffer of its last line.
650+ func (rw * OutputStream ) Flush () {
651+ if rw .lastChar > 0 {
652+ line := string (rw .buf [0 :rw .lastChar ])
653+ rw .streamChan <- line
654+ }
655+ }
Original file line number Diff line number Diff line change @@ -560,7 +560,7 @@ func TestStreamingMultipleLines(t *testing.T) {
560560 }
561561
562562 // Write two short lines
563- input := "foo\n bar\n "
563+ input := "foo\n bar"
564564 n , err := out .Write ([]byte (input ))
565565 if n != len (input ) {
566566 t .Errorf ("Write n = %d, expected %d" , n , len (input ))
@@ -582,6 +582,8 @@ func TestStreamingMultipleLines(t *testing.T) {
582582 t .Errorf ("got line: '%s', expected 'foo'" , gotLine )
583583 }
584584
585+ out .Flush ()
586+
585587 // Get next line
586588 select {
587589 case gotLine = <- lines :
You can’t perform that action at this time.
0 commit comments