src/windows/classes/java/lang/ProcessImpl.java

Print this page




 240     private static final int STILL_ACTIVE = getStillActive();
 241     private static native int getStillActive();
 242 
 243     public int exitValue() {
 244         int exitCode = getExitCodeProcess(handle);
 245         if (exitCode == STILL_ACTIVE)
 246             throw new IllegalThreadStateException("process has not exited");
 247         return exitCode;
 248     }
 249     private static native int getExitCodeProcess(long handle);
 250 
 251     public int waitFor() throws InterruptedException {
 252         waitForInterruptibly(handle);
 253         if (Thread.interrupted())
 254             throw new InterruptedException();
 255         return exitValue();
 256     }
 257     private static native void waitForInterruptibly(long handle);
 258 
 259     public void destroy() { terminateProcess(handle); }




 260     private static native void terminateProcess(long handle);
 261 






 262     /**
 263      * Create a process using the win32 function CreateProcess.
 264      *
 265      * @param cmdstr the Windows commandline
 266      * @param envblock NUL-separated, double-NUL-terminated list of
 267      *        environment strings in VAR=VALUE form
 268      * @param dir the working directory of the process, or null if
 269      *        inheriting the current directory from the parent process
 270      * @param stdHandles array of windows HANDLEs.  Indexes 0, 1, and
 271      *        2 correspond to standard input, standard output and
 272      *        standard error, respectively.  On input, a value of -1
 273      *        means to create a pipe to connect child and parent
 274      *        processes.  On output, a value which is not -1 is the
 275      *        parent pipe handle corresponding to the pipe which has
 276      *        been created.  An element of this array is -1 on input
 277      *        if and only if it is <em>not</em> -1 on output.
 278      * @param redirectErrorStream redirectErrorStream attribute
 279      * @return the native subprocess HANDLE returned by CreateProcess
 280      */
 281     private static native long create(String cmdstr,


 240     private static final int STILL_ACTIVE = getStillActive();
 241     private static native int getStillActive();
 242 
 243     public int exitValue() {
 244         int exitCode = getExitCodeProcess(handle);
 245         if (exitCode == STILL_ACTIVE)
 246             throw new IllegalThreadStateException("process has not exited");
 247         return exitCode;
 248     }
 249     private static native int getExitCodeProcess(long handle);
 250 
 251     public int waitFor() throws InterruptedException {
 252         waitForInterruptibly(handle);
 253         if (Thread.interrupted())
 254             throw new InterruptedException();
 255         return exitValue();
 256     }
 257     private static native void waitForInterruptibly(long handle);
 258 
 259     public void destroy() { terminateProcess(handle); }
 260     public Process destroyForcibly() { 
 261         destroy();
 262         return this;
 263     }
 264     private static native void terminateProcess(long handle);
 265 
 266     @Override
 267     public boolean isAlive() {
 268         return hasProcessExited(handle);
 269     }
 270     private static native boolean hasProcessExited(long handle);
 271 
 272     /**
 273      * Create a process using the win32 function CreateProcess.
 274      *
 275      * @param cmdstr the Windows commandline
 276      * @param envblock NUL-separated, double-NUL-terminated list of
 277      *        environment strings in VAR=VALUE form
 278      * @param dir the working directory of the process, or null if
 279      *        inheriting the current directory from the parent process
 280      * @param stdHandles array of windows HANDLEs.  Indexes 0, 1, and
 281      *        2 correspond to standard input, standard output and
 282      *        standard error, respectively.  On input, a value of -1
 283      *        means to create a pipe to connect child and parent
 284      *        processes.  On output, a value which is not -1 is the
 285      *        parent pipe handle corresponding to the pipe which has
 286      *        been created.  An element of this array is -1 on input
 287      *        if and only if it is <em>not</em> -1 on output.
 288      * @param redirectErrorStream redirectErrorStream attribute
 289      * @return the native subprocess HANDLE returned by CreateProcess
 290      */
 291     private static native long create(String cmdstr,