I've done something similar when I needed to pass single keystrokes into
a Java program: Java won't read keystrokes from a Linux terminal
application, only a LF-terminated string.
So, I wrote a small C program that tweaked stdin to accept individual
keystrokes and passed them, one by one, to the Java app over a socket
connection. My application echoes received characters back to the
keyreader as a primative form of flow control. The only critical thing
with this approach is that the consuming program needs to be up and
expecting a connection before the key reader is launched. I used a shell
script to deal with startup sequencing:
#!/bin/bash
java MyApp &
sleep 1
keyreader
though I could have just as easily invoked ProcessBuilder.start() after
my application had opened its listener socket - or execve() if it was a C
program.
I don't see why the same trick wouldn't work for any other data source as
well as it does for the keyboard.
--
Martin | martin at
Gregorie | gregorie dot org