Search code examples
androidshelladb

How can I redirect android's getevent output to a file?


I'm trying to redirect the getevent command in Android to a file on the device.

I tried. getevent > /path/to/file, but that didn't work. When I CTRL+C'd, the file was empty.

After further investigation, I discovered that it works if I use getevent's -c flag, which tells the process to terminate after a certain number of events are received. This leads me to believe that the problem is related to the fact that I'm killing the process. When I use tee instead of a >, I can see that the output does not show in stdout until the process finishes gracefully.

The problem of course is that getevent never terminates, and I can't use the -c flag because I won't know beforehand how many events are going to be received.

How can I redirect the getevent to a file in such a way that it is there even when the process is killed?

It's fine if the solution requires the device to be rooted.

Edit: I've discovered through further investigation, that if I ensure that at least 25 events have been sent, it writes to the file. But if I ensure 30 events have been sent, only those 25 events will be written to the file. This confirmed my suspicion, that it's a buffer issue.


Solution

  • In the end, I had to write a script calling getevent -c 1 in a loop.