Process: getInputStream()
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
*/
public class MainClass {
public static void main(String[] args) throws Exception{
Runtime r = Runtime.getRuntime();
String[] nargs = { "sh", "-c", "for i in 1 2 3; do echo $i; done" };
Process p = r.exec(nargs);
BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = is.readLine()) != null)
System.out.println(line);
}
}
Related examples in the same category