private void waiterThreadFunc() { if (!WindowsProcesses.nativeWaitFor(nativeProcess)) { // There isn't a lot we can do -- the process is still alive but WaitForMultipleObjects() // failed for some odd reason. We'll pretend it terminated and log a message to jvm.out . System.err.println( "Waiting for process " + WindowsProcesses.nativeGetProcessPid(nativeProcess) + " failed"); } waitLatch.countDown(); }
@Override public synchronized int exitValue() { checkLiveness(); int result = WindowsProcesses.nativeGetExitCode(nativeProcess); String error = WindowsProcesses.nativeGetLastError(nativeProcess); if (!error.isEmpty()) { throw new IllegalStateException(error); } return result; }
@Override public synchronized void finalize() { if (nativeProcess != -1) { WindowsProcesses.nativeDelete(nativeProcess); nativeProcess = -1; } }
private synchronized void writeStream(byte[] b, int off, int len) throws IOException { checkLiveness(); int remaining = len; int currentOffset = off; while (remaining != 0) { int written = WindowsProcesses.nativeWriteStdin(nativeProcess, b, currentOffset, remaining); // I think the Windows API never returns 0 in dwNumberOfBytesWritten // Verify.verify(written != 0); if (written == -1) { throw new IOException(WindowsProcesses.nativeGetLastError(nativeProcess)); } remaining -= written; currentOffset += written; } }
@Override public synchronized boolean destroy() { checkLiveness(); if (!WindowsProcesses.nativeTerminate(nativeProcess)) { return false; } return true; }
private synchronized int readStream(Stream stream, byte b[], int off, int len) throws IOException { checkLiveness(); int result = -1; switch (stream) { case OUT: result = WindowsProcesses.nativeReadStdout(nativeProcess, b, off, len); break; case ERR: result = WindowsProcesses.nativeReadStderr(nativeProcess, b, off, len); break; } if (result == -1) { throw new IOException(WindowsProcesses.nativeGetLastError(nativeProcess)); } return result; }