Win32Process.java 2.2 KB

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