The officially official Devuan Forum!

You are not logged in.

#1 2019-05-16 15:39:07

GNUser
Member
Registered: 2017-03-16
Posts: 465  

limit on number of pipes after long-running command? [SOLVED]

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

#2 2019-05-16 15:41:27

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 290  
Website

Re: limit on number of pipes after long-running command? [SOLVED]

Try

xinput test 9 | awk '/press/{print $3}'

Fabricando fit faber

Offline

#3 2019-05-16 15:42:28

GNUser
Member
Registered: 2017-03-16
Posts: 465  

Re: limit on number of pipes after long-running command? [SOLVED]

That works, of course. But if I add a pipe after that, again: No output even when output is expected.

Offline

#4 2019-05-16 15:47:01

GNUser
Member
Registered: 2017-03-16
Posts: 465  

Re: limit on number of pipes after long-running command? [SOLVED]

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

#5 2019-05-16 16:11:06

GNUser
Member
Registered: 2017-03-16
Posts: 465  

Re: limit on number of pipes after long-running command? [SOLVED]

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

Board footer