I am very interested in doing this as well, I have a set of binaries I
want to run that already run in linux and produce stdout and stdin
calls. I want to have a simple java front end "textview" or something
that reads these and simply dumps them to the screen. Can you
describe in more detail what you did? Seems like you are piping it
with a file, is the java able to run parallel to the jni app so the
text "streams" onto the screen from the native app?
> I'm trying to get an Android application connect directly to stdin andstdoutof a C code segment running in JNI. I tried a few different
> things but ended up using two named pipes, for input and output
> respectively. Essentially I create them using mkfifo() in native code,
> then open each side of the two FIFO files in a separate environment.
> One side from Java and one from C. After this I also redirect stdin
> andstdoutin C to the pipes using dup2(). Here's how it works in C:
>
> mkfifo(out_file, 0666);
> mkfifo(in_file, 0666);
>
> And then when I'm sure the Java thread will open from the other end:
>
> fdo = open(out_file, O_WRONLY);
> fdi = open(in_file, O_RDONLY);
>
> dup2(fdo, 1);
> dup2(fdi, 0);
>
> On the Java side, I open the same files but with reversed operations
> (read for write in c, etc). The real code does have error handling and
> such things as well.
>
> The thing is, forstdout, it works. I can read it through the pipe