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

Print this page




 440         int exitCode = getExitCodeProcess(handle);
 441         if (exitCode == STILL_ACTIVE)
 442             throw new IllegalThreadStateException("process has not exited");
 443         return exitCode;
 444     }
 445     private static native int getExitCodeProcess(long handle);
 446 
 447     public int waitFor() throws InterruptedException {
 448         waitForInterruptibly(handle);
 449         if (Thread.interrupted())
 450             throw new InterruptedException();
 451         return exitValue();
 452     }
 453     private static native void waitForInterruptibly(long handle);
 454 
 455     public void destroy() { terminateProcess(handle); }
 456     private static native void terminateProcess(long handle);
 457 
 458     /**
 459      * Create a process using the win32 function CreateProcess.


 460      *
 461      * @param cmdstr the Windows commandline
 462      * @param envblock NUL-separated, double-NUL-terminated list of
 463      *        environment strings in VAR=VALUE form
 464      * @param dir the working directory of the process, or null if
 465      *        inheriting the current directory from the parent process
 466      * @param stdHandles array of windows HANDLEs.  Indexes 0, 1, and
 467      *        2 correspond to standard input, standard output and
 468      *        standard error, respectively.  On input, a value of -1
 469      *        means to create a pipe to connect child and parent
 470      *        processes.  On output, a value which is not -1 is the
 471      *        parent pipe handle corresponding to the pipe which has
 472      *        been created.  An element of this array is -1 on input
 473      *        if and only if it is <em>not</em> -1 on output.
 474      * @param redirectErrorStream redirectErrorStream attribute
 475      * @return the native subprocess HANDLE returned by CreateProcess
 476      */
 477     private static native long create(String cmdstr,
 478                                       String envblock,
 479                                       String dir,
 480                                       long[] stdHandles,
 481                                       boolean redirectErrorStream)
 482         throws IOException;
 483 
 484     /**
 485      * Opens a file for atomic append. The file is created if it doesn't
 486      * already exist.
 487      *
 488      * @param file the file to open or create
 489      * @return the native HANDLE
 490      */
 491     private static native long openForAtomicAppend(String path)
 492         throws IOException;
 493 
 494     private static native boolean closeHandle(long handle);
 495 }


 440         int exitCode = getExitCodeProcess(handle);
 441         if (exitCode == STILL_ACTIVE)
 442             throw new IllegalThreadStateException("process has not exited");
 443         return exitCode;
 444     }
 445     private static native int getExitCodeProcess(long handle);
 446 
 447     public int waitFor() throws InterruptedException {
 448         waitForInterruptibly(handle);
 449         if (Thread.interrupted())
 450             throw new InterruptedException();
 451         return exitValue();
 452     }
 453     private static native void waitForInterruptibly(long handle);
 454 
 455     public void destroy() { terminateProcess(handle); }
 456     private static native void terminateProcess(long handle);
 457 
 458     /**
 459      * Create a process using the win32 function CreateProcess.
 460      * The method is synchronized due to MS kb315939 problem.
 461      * All native handles should restore the inherit flag at the end of call.
 462      *
 463      * @param cmdstr the Windows command line
 464      * @param envblock NUL-separated, double-NUL-terminated list of
 465      *        environment strings in VAR=VALUE form
 466      * @param dir the working directory of the process, or null if
 467      *        inheriting the current directory from the parent process
 468      * @param stdHandles array of windows HANDLEs.  Indexes 0, 1, and
 469      *        2 correspond to standard input, standard output and
 470      *        standard error, respectively.  On input, a value of -1
 471      *        means to create a pipe to connect child and parent
 472      *        processes.  On output, a value which is not -1 is the
 473      *        parent pipe handle corresponding to the pipe which has
 474      *        been created.  An element of this array is -1 on input
 475      *        if and only if it is <em>not</em> -1 on output.
 476      * @param redirectErrorStream redirectErrorStream attribute
 477      * @return the native subprocess HANDLE returned by CreateProcess
 478      */
 479     private static synchronized native long create(String cmdstr,
 480                                       String envblock,
 481                                       String dir,
 482                                       long[] stdHandles,
 483                                       boolean redirectErrorStream)
 484         throws IOException;
 485 
 486     /**
 487      * Opens a file for atomic append. The file is created if it doesn't
 488      * already exist.
 489      *
 490      * @param file the file to open or create
 491      * @return the native HANDLE
 492      */
 493     private static native long openForAtomicAppend(String path)
 494         throws IOException;
 495 
 496     private static native boolean closeHandle(long handle);
 497 }