Merged gcj-eclipse branch to trunk.
[gcc.git] / libjava / java / lang / Win32Process.java
1 // Win32Process.java - Subclass of Process for Win32 systems.
2
3 /* Copyright (C) 2002, 2003, 2006 Free Software Foundation
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 package java.lang;
12
13 import java.io.File;
14 import java.io.InputStream;
15 import java.io.OutputStream;
16 import java.io.IOException;
17
18 /**
19 * @author Adam Megacz
20 * @date Feb 24, 2002
21 */
22
23 // This is entirely internal to our implementation.
24
25 final class Win32Process extends Process
26 {
27 public native void destroy ();
28
29 public int exitValue ()
30 {
31 if (! hasExited ())
32 throw new IllegalThreadStateException ("Process has not exited");
33
34 return exitCode;
35 }
36
37 public InputStream getErrorStream ()
38 {
39 return errorStream;
40 }
41
42 public InputStream getInputStream ()
43 {
44 return inputStream;
45 }
46
47 public OutputStream getOutputStream ()
48 {
49 return outputStream;
50 }
51
52 public native int waitFor () throws InterruptedException;
53
54 public Win32Process (String[] progarray,
55 String[] envp,
56 File dir)
57 throws IOException
58 {
59 for (int i = 0; i < progarray.length; i++)
60 {
61 String s = progarray[i];
62
63 if ( (s.indexOf (' ') >= 0) || (s.indexOf ('\t') >= 0))
64 progarray[i] = "\"" + s + "\"";
65 }
66
67 startProcess (progarray, envp, dir);
68 }
69
70 // The standard streams (stdin, stdout and stderr, respectively)
71 // of the child as seen by the parent process.
72 private OutputStream outputStream;
73 private InputStream inputStream;
74 private InputStream errorStream;
75
76 // Handle to the child process - cast to HANDLE before use.
77 private int procHandle;
78
79 // Exit code of the child if it has exited.
80 private int exitCode;
81
82 private native boolean hasExited ();
83 private native void startProcess (String[] progarray,
84 String[] envp,
85 File dir)
86 throws IOException;
87 private native void cleanup ();
88 }