home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / java / lang / Win32Process.java < prev   
Encoding:
Java Source  |  1997-01-27  |  2.5 KB  |  85 lines

  1. /*
  2.  * @(#)Win32Process.java    1.6 95/11/21 David Connelly
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.lang;
  21.  
  22. import java.io.*; 
  23.  
  24. public class Win32Process extends Process {
  25.     private int handle = 0;
  26.     private FileDescriptor stdin_fd;
  27.     private FileDescriptor stdout_fd;
  28.     private FileDescriptor stderr_fd;
  29.     private OutputStream stdin_stream;
  30.     private InputStream stdout_stream;
  31.     private InputStream stderr_stream;
  32.  
  33.     Win32Process(String cmd[], String env[]) throws Exception {
  34.     if (cmd.length < 1) {
  35.         throw new IllegalArgumentException();
  36.     }
  37.     StringBuffer cmdbuf = new StringBuffer(cmd[0]);
  38.     for (int i = 1; i < cmd.length; i++) {
  39.         cmdbuf.append(' ').append(cmd[i]);
  40.     }
  41.     String cmdstr = cmdbuf.toString();
  42.  
  43.     String envstr = null;
  44.     if (env != null) {
  45.         StringBuffer envbuf = new StringBuffer();
  46.         for (int i = 0; i < env.length; i++) {
  47.         envbuf.append(env[i]).append('\0');
  48.         }
  49.         envstr = envbuf.toString();
  50.     }
  51.  
  52.     stdin_fd = new FileDescriptor();
  53.     stdout_fd = new FileDescriptor();
  54.     stderr_fd = new FileDescriptor();
  55.     
  56.     create(cmdstr, envstr);
  57.     stdin_stream = new BufferedOutputStream(new FileOutputStream(stdin_fd));
  58.     stdout_stream = new BufferedInputStream(new FileInputStream(stdout_fd));
  59.     stderr_stream = new FileInputStream(stderr_fd);
  60.     }
  61.  
  62.     public OutputStream getOutputStream() {
  63.     return stdin_stream;
  64.     }
  65.  
  66.     public InputStream getInputStream() {
  67.     return stdout_stream;
  68.     }
  69.  
  70.     public InputStream getErrorStream() {
  71.     return stderr_stream;
  72.     }
  73.  
  74.     public void finalize() {
  75.     close();
  76.     }
  77.  
  78.     public native int exitValue();
  79.     public native int waitFor();
  80.     public native void destroy();
  81.  
  82.     private native void create(String cmdstr, String envstr);
  83.     private native void close();
  84. }
  85.