1 // Create a process and read from its standard output.
2 //
3 import java.io.BufferedReader;
4 import java.io.InputStream;
5 import java.io.InputStreamReader;
6 
7 
8 public class Process_1
9 {
main(String[] args)10   public static void main(String[] args)
11   {
12     try
13       {
14 	Runtime r = Runtime.getRuntime();
15 	String s = "Hello World";
16 	String[] a = { "echo", s };
17 	Process p = r.exec(a);
18 	InputStream is = p.getInputStream();
19 	InputStreamReader isr = new InputStreamReader(is);
20 	BufferedReader br = new BufferedReader(isr);
21 	String result = br.readLine();
22 	if (! s.equals(result))
23 	  {
24 	    System.out.println("bad 1");
25 	    return;
26 	  }
27 	result = br.readLine();
28 	if (result != null)
29 	  {
30 	    System.out.println("bad 2");
31 	    return;
32 	  }
33 	int c = p.waitFor();
34 	System.out.println(c == 0 ? "ok" : "bad 3");
35       }
36     catch (Exception ex)
37       {
38 	System.out.println(ex.toString());
39       }
40   }
41 }
42