3

Some programs do not read from stdin (such as dmesg or adb logcat). I usually press Return a few times to provide a separation between log lines. When I interrupt the command directly in the shell, everything works satisfactory.

However, when the programs terminate themselves (because the connection for adb logcat gets lost for example), the shell starts processing all lines I have entered. This usually looks like this:

user@host$ 
user@host$ 
user@host$ 
user@host$ 
user@host$ # I broke something here
user@host$ 
user@host$ 
user@host$ 
user@host$ TODO LOOK AT THIS
bash: TODO: command not found
user@host$ 
user@host$ 
user@host$ 
user@host$ 
user@host$ 
user@host$ # adb is about to get killed...
user@host$

As you can understand, having Bash execute all these lines is quite useless and shifts the last remaining output. Is there a way to consume stdin even when the process terminates?

3

This seems to work:

dmesg -Hw; read -t .01 -d ""

This command will (after dmesg has terminated) run the Bash built-in read to consume all input (no delimiter instead of a newline, -d ""). The -t .01 argument causes the read command to timeout after 0.01 seconds so that the command returns quickly.

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.