Need advise on how to implement pipes in Java. Eg,
echo "test"|wc
I need to show results of the above pipe example.
I have tried this:
public class myRunner {
private static final String[] cmd = new String[] {"wc"};
public static void main(String[] args){
try {
ProcessBuilder pb = new ProcessBuilder( cmd );
pb.redirectErrorStream(true);
Process process = pb.start();
OutputStream os = process.getOutputStream();
os.write("echo test".getBytes() );
os.close();
}catch (IOException e){
e.printStackTrace();
}
How can I view the output of wc
output?
I believe another one of the library i can use is PipedInputStream
/PipedOutputStream
. Can anyone show an example on how to use it? Am quite confused. thanks