Implemented ProcessLauncher on Windows.
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user