2
1
I run some program in git bash terminal on windows and redirect output to grep to search for specific keywords. Problem is that the output is delayed, so it looks like the terminal waits for a chunk of output and then displays it. If I remove grep, there is no delay. How to fix the delay when the output is redirected to grep?
1
Have you tried this? Something like
– NonlinearFruit – 2016-01-21T14:54:32.490git foo | grep --line-buffered my_pattern
1The buffering is in
git
's output routines and there is very little you can do: if you write your own program you can flush output after each write, so the only solution I can see is to compilegit
from source after modifying its output function. Is it worth it? – AFH – 2016-01-21T15:39:05.427NonlinearFruit That does not solve the problem. @AFH Why do you think it's git's problem? I don't actually grep git output. – user544582 – 2016-01-22T08:40:25.793
1@user544582 - Your question is unclearly phrased, and both I and @NonlinerFruit understood that
git
was the program whose output was being directed togrep
; but whatever program you are running, the same argument applies. Redirected output will be buffered and will not be written until (1) the buffer is filled, (2) the output is specifically flushed (done automatically when opened withO_SYNC
orO_DSYNC
option), (3) the output file is repositioned outside the buffer, or (4) the file is closed. – AFH – 2016-01-22T12:59:33.353@AFH I said I run some program in git bash terminal, how is that unclear? The problems is that I only get binary of that program and cannot change its source. Also, output is not buffered if ran under linux, only on windows systems inside git bash terminal. – user544582 – 2016-01-25T09:21:04.003
Does the same thing happen when you run the same commands in
cmd
? If so, then without the source code you are unlikely to find a solution, and the difference in behaviour between Linux and Windows will probably be caused by whatever compatibility library was used to port the program. If there is a difference, then it must depend on how piping is implemented in thebash
port, and the source of this will be available, or as a work-round you can callcmd
frombash
. – AFH – 2016-01-25T13:20:29.853