Beispiel #1
0
  @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;
  }
Beispiel #2
0
  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;
    }
  }
Beispiel #3
0
  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;
  }