Hi Thorsten,
On Fri, 13 Apr 2012, Thorsten Sy wrote:
> I use two (command line) programs to create/modify images and I want to
> avoid saving these image in-between. I.e. I want to use such an
> configuration:
>
> some program (Pipe) ImageJ
>
> The program writes the image to stdout and ImageJ should read it from stdin.
>
> Is it possible for ImageJ to read an image through a pipe (stdin)?
It is possible, by writing a Java program (you might get away with a
Javascript, Beanshell always works, but Macro is out of the question).
You would need to use the exec() method:
http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#exec(java.lang.String[],%20java.lang.String[],%20java.io.File)
to construct a Process instance:
http://docs.oracle.com/javase/6/docs/api/java/lang/Process.htmland then access the *OutputStream* using getOutputStream():
http://docs.oracle.com/javase/6/docs/api/java/lang/Process.html#getOutputStream()
It is a bit confusingly named, as the output stream is the stream you can
write into, but it is actually the stdin of the process.
An example how to use it can be found here:
http://fiji.sc/SimpleExecuter.javaThe SimpleExecuter class is meant to call programs quickly and get their
output into the ImageJ1 Log window (but of course, it is general enough
that you can do with it what you want).
You probably want to reimplement this, though, and feed the input to it
while processing its output (and checking for error conditions). The
important point to keep in mind is that you need to handle either the
input or the output in a separate thread to avoid thread-lock. And in case
of an error, the other thread has to be interrupted and joined.
Ciao,
Johannes