I have a command that gives a list of files (like find).
For each of those files i want to do something in Java:
find ./files <some restrictions> | java -jar processor.jar
how can i read from this unnamed / anonymous Pipe?
I have a command that gives a list of files (like find).
For each of those files i want to do something in Java:
find ./files <some restrictions> | java -jar processor.jar
how can i read from this unnamed / anonymous Pipe?
Quite simple really; using a pipe in a shell means that the standard output of the process on the left hand of a pipe is what the standard input of the process on the right hand of the pipe will read.
Therefore, the Java process needs only read stdin, and in Java, this is System.in
.
As to using the find
command, it's fine, really; but if you use Java 7+ you might consider using a FileVisitor
instead and Files.walkFileTree()
.