0

I need to read data sent by UDP. I use nc -ul 50000. It keeps running even after having received a line. I want to read every line as it arrives. How can I do that?

An answer to another question on Stackexchange suggested using something like

while read VAR
do
my_command
done < <(nc -ul 50000)

but that doesn't do the trick... doesn't read anything. I am really grateful for any help you can provide cause I really don't know how this could be done.

  • See also: https://stackoverflow.com/questions/11337041/force-line-buffering-of-stdout-when-piping-to-tee – cdarke Feb 15 '18 at 09:04

1 Answers1

1

You can force a program to use line-buffered or unbuffered output with

stdbuf -o L nc -ul 50000

(replace the "L" with "0" (zero) to get fully unbuffered output)

simon3270
  • 722
  • 1
  • 5
  • 8
  • `stdbuf` is not POSIX, but part of GNU-coreutils. – cdarke Feb 15 '18 at 09:02
  • `while read IN; do echo $IN; notify-send $IN; done < <(stdbuf -o L nc -ul 50000)` should then print every arriving text as it arrives, shouldn't it? Unfortunately, I get not output from it. – user6287736 Feb 15 '18 at 12:46
  • Do you know that the nc command is receiving messages? What happens if you just run the `stdbuf -o L nc -ul 50000` command like I had - does it print out messages? (edited to add full command) – simon3270 Feb 15 '18 at 14:23