Implemented ProcessLauncher on Windows.

This commit is contained in:
Adam Murdoch
2013-02-20 15:03:39 +11:00
parent 18c0d99835
commit c67453eef6
2 changed files with 39 additions and 39 deletions

View File

@@ -1,30 +1,30 @@
package net.rubygrapefruit.platform.internal;
import net.rubygrapefruit.platform.NativeException;
import net.rubygrapefruit.platform.ProcessLauncher;
import net.rubygrapefruit.platform.internal.jni.WindowsHandleFunctions;
public class WindowsProcessLauncher implements ProcessLauncher {
private final ProcessLauncher launcher;
public WindowsProcessLauncher(ProcessLauncher launcher) {
this.launcher = launcher;
}
public Process start(ProcessBuilder processBuilder) throws NativeException {
FunctionResult result = new FunctionResult();
WindowsHandleFunctions.markStandardHandlesUninheritable(result);
if (result.isFailed()) {
throw new NativeException(String.format("Could not start '%s': %s", processBuilder.command().get(0),
result.getMessage()));
}
try {
return launcher.start(processBuilder);
} finally {
WindowsHandleFunctions.restoreStandardHandles(result);
if (result.isFailed()) {
throw new NativeException(String.format("Could not restore process handles: %s", result.getMessage()));
}
}
}
}
package net.rubygrapefruit.platform.internal;
import net.rubygrapefruit.platform.NativeException;
import net.rubygrapefruit.platform.ProcessLauncher;
import net.rubygrapefruit.platform.internal.jni.WindowsHandleFunctions;
public class WindowsProcessLauncher implements ProcessLauncher {
private final ProcessLauncher launcher;
public WindowsProcessLauncher(ProcessLauncher launcher) {
this.launcher = launcher;
}
public Process start(ProcessBuilder processBuilder) throws NativeException {
FunctionResult result = new FunctionResult();
WindowsHandleFunctions.markStandardHandlesUninheritable(result);
if (result.isFailed()) {
throw new NativeException(String.format("Could not start '%s': %s", processBuilder.command().get(0),
result.getMessage()));
}
try {
return launcher.start(processBuilder);
} finally {
WindowsHandleFunctions.restoreStandardHandles(result);
if (result.isFailed()) {
throw new NativeException(String.format("Could not restore process handles: %s", result.getMessage()));
}
}
}
}

View File

@@ -1,9 +1,9 @@
package net.rubygrapefruit.platform.internal.jni;
import net.rubygrapefruit.platform.internal.FunctionResult;
public class WindowsHandleFunctions {
public static native void markStandardHandlesUninheritable(FunctionResult result);
public static native void restoreStandardHandles(FunctionResult result);
}
package net.rubygrapefruit.platform.internal.jni;
import net.rubygrapefruit.platform.internal.FunctionResult;
public class WindowsHandleFunctions {
public static native void markStandardHandlesUninheritable(FunctionResult result);
public static native void restoreStandardHandles(FunctionResult result);
}