home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-27 | 2.5 KB | 85 lines |
- /*
- * @(#)Win32Process.java 1.6 95/11/21 David Connelly
- *
- * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- package java.lang;
-
- import java.io.*;
-
- public class Win32Process extends Process {
- private int handle = 0;
- private FileDescriptor stdin_fd;
- private FileDescriptor stdout_fd;
- private FileDescriptor stderr_fd;
- private OutputStream stdin_stream;
- private InputStream stdout_stream;
- private InputStream stderr_stream;
-
- Win32Process(String cmd[], String env[]) throws Exception {
- if (cmd.length < 1) {
- throw new IllegalArgumentException();
- }
- StringBuffer cmdbuf = new StringBuffer(cmd[0]);
- for (int i = 1; i < cmd.length; i++) {
- cmdbuf.append(' ').append(cmd[i]);
- }
- String cmdstr = cmdbuf.toString();
-
- String envstr = null;
- if (env != null) {
- StringBuffer envbuf = new StringBuffer();
- for (int i = 0; i < env.length; i++) {
- envbuf.append(env[i]).append('\0');
- }
- envstr = envbuf.toString();
- }
-
- stdin_fd = new FileDescriptor();
- stdout_fd = new FileDescriptor();
- stderr_fd = new FileDescriptor();
-
- create(cmdstr, envstr);
- stdin_stream = new BufferedOutputStream(new FileOutputStream(stdin_fd));
- stdout_stream = new BufferedInputStream(new FileInputStream(stdout_fd));
- stderr_stream = new FileInputStream(stderr_fd);
- }
-
- public OutputStream getOutputStream() {
- return stdin_stream;
- }
-
- public InputStream getInputStream() {
- return stdout_stream;
- }
-
- public InputStream getErrorStream() {
- return stderr_stream;
- }
-
- public void finalize() {
- close();
- }
-
- public native int exitValue();
- public native int waitFor();
- public native void destroy();
-
- private native void create(String cmdstr, String envstr);
- private native void close();
- }
-