- while (!out_buf.Extract(output)) {
- // buffer exhausted, fetch more data
- int len = proc.ReadOut(out_buf.WriteHead(), out_buf.Remain(), 5000);
- if (len == 0) {
- return;
+ output.clear();
+ for (const auto &line : past_out) {
+ output += line;
+ output += '\n';
+ }
+ past_out.clear();
+ string line;
+ while (true) {
+ if (out_buf.Extract(line)) {
+ output += line;
+ output += '\n';
+ } else {
+ // buffer exhausted, fetch more data
+ int len = proc.ReadOut(out_buf.WriteHead(), out_buf.Remain(), 5000);
+ if (len == 0) {
+ // eof
+ return;
+ }
+ out_buf.Update(len);