I want to read input and prints only the output like
(Read 1 2 3 4 5,Prints 1 2 3 4 5) using shell execute in java
when i run the followining code output looks like this "echo 1 2 3 4 5| java task4". My class name is task4.
I don't really know what do. any suggestion?
String command="echo 1 2 3 4 5 | java task4";
Process cmdProc = Runtime.getRuntime().exec(command);
BufferedReader stdoutReader = new BufferedReader(
new InputStreamReader(cmdProc.getInputStream()));
String line;
while ((line = stdoutReader.readLine()) != null) {
// process procs standard output here
System.out.println(line);
}
BufferedReader stderrReader = new BufferedReader(
new InputStreamReader(cmdProc.getErrorStream()));
String line1;
while ((line1 = stderrReader.readLine()) != null) {
// process procs standard error here
}
int retValue = cmdProc.exitValue();