1

This question maybe not related to Emacs only, but to all development environment that use Console for its debugging process. Here is the problem. I use Eshell to run the application we are being developed. It's a J2ME application. And for debugging, we just use System.out.println(). And now, suppose I want to allow only text that started with Eko: to be displayed in the console (interactively), is it possible?

I installed Cygwin in my Windows environment, and try to grep the output like this : run | grep Eko:. It surely filtered only output with Eko: as the beginning, but it's not interactive. The output suppressed until the application quit. Well, that's useless anyway.

Is it possible to do it? What I mean is, we don't have to touch the application code itself?

I tag to linux also, because maybe some guys in Linux know the answer.

Many thanks!

1 Answer 1

1

The short: Try adding --line-buffered to your grep command.

The long: I assume that your application is flushing its output stream with every System.out.println(), and that grep has the lines available to read immediately, but is choosing to buffer output until it has 'enough' output saved up to make writing make sense. (This is typically 4k or 8k of data, which could be several hundred lines, depending upon your line length.)

This buffering makes great sense when the output is another program in the pipeline; reducing needless context switches is a great way to improve program throughput.

But if your printing is slow enough that it doesn't fill the buffer quickly enough for 'real time' output, then switching to line-buffered output might fix it.

4
  • Excellent! And a very detailed explanation... Many thanks. This, will help us a lot here. Thanks
    – swdev
    Mar 4, 2011 at 4:19
  • By the way, I just test grep without --line-buffered in DOS Command Window. It works. So, why do we need --line-buffered inside Emacs Shell, but not in DOS Command Window? I am sorry, if in your explanation you already explain it. I just got time to understand it :) Many thanks
    – swdev
    Mar 4, 2011 at 4:32
  • 1
    @swdev: with a terminal as output the standard C libraries will set the stdout stdio stream to line-buffered. But when the stdout stream is set to a pipe (as I imagine it is in the Emacs buffer), then the C library will perform block buffering instead. The default is to call fstat(2) on the file descriptor and use st_blksize bytes for the buffer. This is typically 4k or 8k, but other values are possible. The setvbuf(3) manpage has all the gritty details. :)
    – sarnold
    Mar 4, 2011 at 4:37
  • ... okay ^_^ I didn't do a lot of code on C. That should be very awesome... :)
    – swdev
    Mar 4, 2011 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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