mardi 30 décembre 2014

How to grep netcat output


I'm trying to grep live text stream from netcat, but it doesn't work for me:



netcat localhost 9090 | grep sender


returns nothing, but I'm sure that it should.


If I redirect the netcat output to a file and add some delays (simulate real environment) - then it works:



$ (sleep 5; cat netcat_output; sleep 5) | grep sender

{"jsonrpc":"2.0","method":"GUI.OnScreensaverDeactivated","params":{"data": "shuttingdown":false},"sender":"xbmc"}}


I also tried to add --line-buffered but w/o success.


What I do wrong?


Edit:


I noticed the same issue with sed, the output is empty.


But, for instance, hexdump converts text to hex live:



$ netcat localhost 9090 | hexdump -C
00000000 7b 22 6a 73 6f 6e 72 70 63 22 3a 22 32 2e 30 22 |{"jsonrpc":"2.0"|
00000010 2c 22 6d 65 74 68 6f 64 22 3a 22 50 6c 61 79 65 |,"method":"Playe|
00000020 72 2e 4f 6e 50 6c 61 79 22 2c 22 70 61 72 61 6d |r.OnPlay","param|
00000030 73 22 3a 7b 22 64 61 74 61 22 3a 7b 22 69 74 65 |s":{"data":{"ite|
00000040 6d 22 3a 7b 22 69 64 22 3a 36 2c 22 74 79 70 65 |m":{"id":6,"type|
00000050 22 3a 22 6d 6f 76 69 65 22 7d 2c 22 70 6c 61 79 |":"movie"},"play|
00000060 65 72 22 3a 7b 22 70 6c 61 79 65 72 69 64 22 3a |er":{"playerid":|
00000070 31 2c 22 73 70 65 65 64 22 3a 31 7d 7d 2c 22 73 |1,"speed":1}},"s|


Aucun commentaire:

Enregistrer un commentaire