Issue
I have a node script which would normally be called like
node emitter.js "some message"
Now i am using trl_fm and multimon_ng to receive and decode some radio messages. I managed to redirect the output to /dev/stdin by using a command like this:
rtl_fm -M fm -f 81.200M -s 21 | multimon-ng -t raw -a POCSAG2400 -f alpha /dev/stdin
This way I am getting kind of a console-log where the decoded messages are printed out on a line each when they have been received.
What I am trying to achieve is to call emitter.js
everytime a message is received and pass this message as an parameter to emitter.js
, but i just can't figure out how to get this to work.
things I have tried:
rtl_fm -M fm -f 81.200M -s 21 | multimon-ng -t raw -a POCSAG2400 -f alpha /dev/stdin | node emitter.js
rtl_fm -M fm -f 81.200M -s 21 | multimon-ng -t raw -a POCSAG2400 -f alpha /dev/stdin > node emitter.js
rtl_fm -M fm -f 81.200M -s 21 | multimon-ng -t raw -a POCSAG2400 -f alpha /dev/stdin >> node emitter.js
Is there any way to get this to work?
Solution
You can hook up everything with a bit of shell scripting:
#!/bin/sh
rtl_fm -M fm -f 81.200M -s 21 | \
multimon-ng -t raw -a POCSAG2400 -f alpha /dev/stdin | \
while read message
do
node emitter.js "$message"
done
Or you could modify emitter.js
so it would read messages from stdin instead of using command line arguments, in which case you could pipe to the Node process directly (and it also would remove the need to start a new Node process for each incoming message).
Answered By - robertklep Answer Checked By - Robin (WPSolving Admin)