Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / testsuite / libjava.lang / Process_3.java
blob669e1dc7e293a2b3c1c9cf5831559997dafee762
1 // Create a process and pipe data through it. waitFor() the process
2 // in a different thread than the one that created it.
3 import java.io.BufferedReader;
4 import java.io.InputStream;
5 import java.io.InputStreamReader;
6 import java.io.OutputStream;
7 import java.io.PrintStream;
10 public class Process_3 implements Runnable
12 Process p;
14 public void run()
16 try
18 Runtime r = Runtime.getRuntime();
19 String[] a = { "sed", "-e", "s/Hello/Goodbye/" };
20 synchronized (this)
22 p = r.exec(a);
23 this.notifyAll();
25 OutputStream os = p.getOutputStream();
26 PrintStream ps = new PrintStream(os);
27 ps.println("Hello World");
28 ps.close();
30 catch (Exception ex)
32 System.out.println(ex.toString());
36 public static void main(String[] args)
38 try
40 Process_3 p3 = new Process_3();
41 Thread t = new Thread(p3);
42 t.start();
43 synchronized (p3)
45 while (p3.p == null)
46 p3.wait();
49 InputStream is = p3.p.getInputStream();
50 InputStreamReader isr = new InputStreamReader(is);
51 BufferedReader br = new BufferedReader(isr);
52 String result = br.readLine();
53 if (! "Goodbye World".equals(result))
55 System.out.println("bad 1");
56 return;
58 result = br.readLine();
59 if (result != null)
61 System.out.println("bad 2");
62 return;
64 int c = p3.p.waitFor();
65 System.out.println(c == 0 ? "ok" : "bad 3");
67 catch (Exception ex)
69 System.out.println(ex.toString());