8

If there a way to read the output of a subprocess line by line, or at least to get it in small batches?

I have a subprocess doing work in the background, and printing a line every time it completes a task. There are many such small tasks, so I would like to show a progress indicator; unfortunately, my filter function receives output in batches of 10 to 20 lines, which makes the progress display much more jittery than it really is.

When I run that same process as a compile process, the output is displayed smoothly; I can't figure the trick that compilation-mode uses to achieve this.

Clément
  • 3,924
  • 1
  • 22
  • 37
  • Is your filter doing anything special to restrict the flow -- have you tried just printing messages for every "string" that goes through the filter to see what the `string`s look like? E.g., `(defun my-process-filter (proc string) (message "%s\n" string))` I added a new-line so the `string`s are clearly separated. – lawlist Aug 04 '15 at 01:17
  • 1
    Nope, nothing special; I'm essentially just printing the messages. – Clément Aug 04 '15 at 05:19
  • This, most likely, is a property of the spawned process. It needs to flush its output more often. Compilers typically emit error messages on lstderr, which is line based. – Lindydancer Aug 04 '15 at 11:40
  • @Lindydancer: I wrote the tool that gets spawned, and it already flushes after each line. – Clément Aug 04 '15 at 20:17
  • 1
    Maybe try using `compilation-start` and remove code until you see the jittery effect? BTW, I don't think anyone will be help you with this question unless you post enough code to reproduce this. – npostavs Oct 05 '15 at 03:58

1 Answers1

1

The only thing I know of for this is setting process-adaptive-read-buffering to nil before starting the process. I don't know whether this will help with your situation or not.

Tom Tromey
  • 759
  • 4
  • 8
  • Ah, yes, I tried that; no luck though. The surprising part is that calling the process through compilation-mode seems to work much better; I wonder what happens there. – Clément Aug 06 '15 at 16:51