You are not logged in.
I'm trying to create a minimal, crude keylogger for X using only a shell script. I was quickly stumped: Why do these two commands entered in a terminal emulator produce output when I press some keys on my keyboard:
$ xinput test 9 | grep press
$ xinput test 9 | awk '{print $3}'
...but this command produces no output:
$ xinput test 9 | grep press | awk '{print $3}'
?
It seems after the first command I can use only one pipe--if I add a second pipe, I get no output even when output is expected. What gives?
(BTW, 9 is the id of my keyboard, which I found by running xinput list. My shell is bash version 4.4.12)
Last edited by GNUser (2019-05-16 16:13:58)
Offline
Try
xinput test 9 | awk '/press/{print $3}'
Brianna Ghey — Rest In Power
Offline
That works, of course. But if I add a pipe after that, again: No output even when output is expected.
Offline
For example, here is what I get if I type devuan after the command:
$ xinput test 9 | awk '/press/ {print $3}'
40
26
55
30
38
57
Why does the following produce no output when I type devuan, even though there is an n in there?
$ xinput test 9 | awk '/press/ {print $3}' | grep 57
That's what I'm trying to understand: Why is there no output at all when I use a second pipe, even when output is expected? Is it a buffering issue?
Last edited by GNUser (2019-05-16 15:48:59)
Offline
It was a buffering issue. I found this helpful thread:
https://unix.stackexchange.com/question … ng-in-pipe
I can confirm that either of these pipelines work as expected:
xinput test 9 | stdbuf -o0 grep release | awk '{print $3}'
xinput test 9 | unbuffer -p grep release | awk '{print $3}'
Last edited by GNUser (2019-05-16 16:12:37)
Offline