@@ -114,24 +114,32 @@ func runCommandWithOutput(cmd *exec.Cmd, outputCh chan string, doneCh chan bool)
114
114
defer close (dataReadCh )
115
115
116
116
go func () {
117
- defer func () {
118
- dataReadCh <- true
119
- }()
120
-
121
117
reader := bufio .NewReader (cmdOutput )
118
+ readBuffer := 1024
122
119
123
120
for {
124
- line , err := reader .ReadString ('\n' )
125
- if errors .Is (err , io .EOF ) {
121
+ data , err := reader .Peek (readBuffer )
122
+ switch {
123
+ case errors .Is (err , io .EOF ):
126
124
log .Infoln ("Read ended with EOF" )
127
- break
128
- } else if err != nil {
129
- log .Infoln ("Read ended with error" , err )
130
- outputCh <- fmt .Sprintf ("Error reading from stdout: %v" , err )
125
+ outputCh <- string (data )
126
+ dataReadCh <- true
131
127
return
128
+ case errors .Is (err , io .ErrShortBuffer ):
129
+ log .Infoln ("Shorter read than wanted" , err , data )
130
+ if len (data ) != 0 {
131
+ log .Infoln ("Not empty" , data )
132
+ outputCh <- string (data )
133
+ _ , err := reader .Discard (len (data ))
134
+ if err != nil {
135
+ // TODO: what should I do if I want to move the reader
136
+ // If I do nothing it can only cause it to be read twice
137
+ log .Errorln ("Discard failed" , err )
138
+ }
139
+ }
140
+ default :
141
+ log .Infoln (data , err )
132
142
}
133
- log .Infoln ("Read line: " , line )
134
- outputCh <- line
135
143
}
136
144
}()
137
145
@@ -174,18 +182,15 @@ func executeCommandWithProgress(command string, interpreter string, variables ma
174
182
for {
175
183
select {
176
184
case output := <- outputCh :
177
- // TODO: this has to be sent to dispatcher back to report to UI
178
- // the idea is to send partial output if buffer with given size sent the output to channel
179
- log .Info (output )
180
-
181
- // Append partial to all output
182
185
bufferedOutput += output
183
186
case <- ticker .C :
184
187
// NOTE: If just message without output is also okay we could send just still running
185
188
log .Infoln ("Still running ..." )
189
+ log .Infoln (bufferedOutput )
186
190
case <- doneCh :
187
191
// Execution is done
188
192
log .Infoln ("Execution done ..." )
193
+ log .Infoln (bufferedOutput )
189
194
return bufferedOutput
190
195
}
191
196
}
0 commit comments