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.

  • 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 strings look like? E.g., (defun my-process-filter (proc string) (message "%s\n" string)) I added a new-line so the strings are clearly separated. – lawlist Aug 4 '15 at 1:17
  • 1
    Nope, nothing special; I'm essentially just printing the messages. – Clément Aug 4 '15 at 5: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 4 '15 at 11:40
  • @Lindydancer: I wrote the tool that gets spawned, and it already flushes after each line. – Clément Aug 4 '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 5 '15 at 3:58

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.

  • 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 6 '15 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.