Implemented ProcessLauncher on Windows.
This commit is contained in:
@@ -1,30 +1,30 @@
|
|||||||
package net.rubygrapefruit.platform.internal;
|
package net.rubygrapefruit.platform.internal;
|
||||||
|
|
||||||
import net.rubygrapefruit.platform.NativeException;
|
import net.rubygrapefruit.platform.NativeException;
|
||||||
import net.rubygrapefruit.platform.ProcessLauncher;
|
import net.rubygrapefruit.platform.ProcessLauncher;
|
||||||
import net.rubygrapefruit.platform.internal.jni.WindowsHandleFunctions;
|
import net.rubygrapefruit.platform.internal.jni.WindowsHandleFunctions;
|
||||||
|
|
||||||
public class WindowsProcessLauncher implements ProcessLauncher {
|
public class WindowsProcessLauncher implements ProcessLauncher {
|
||||||
private final ProcessLauncher launcher;
|
private final ProcessLauncher launcher;
|
||||||
|
|
||||||
public WindowsProcessLauncher(ProcessLauncher launcher) {
|
public WindowsProcessLauncher(ProcessLauncher launcher) {
|
||||||
this.launcher = launcher;
|
this.launcher = launcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Process start(ProcessBuilder processBuilder) throws NativeException {
|
public Process start(ProcessBuilder processBuilder) throws NativeException {
|
||||||
FunctionResult result = new FunctionResult();
|
FunctionResult result = new FunctionResult();
|
||||||
WindowsHandleFunctions.markStandardHandlesUninheritable(result);
|
WindowsHandleFunctions.markStandardHandlesUninheritable(result);
|
||||||
if (result.isFailed()) {
|
if (result.isFailed()) {
|
||||||
throw new NativeException(String.format("Could not start '%s': %s", processBuilder.command().get(0),
|
throw new NativeException(String.format("Could not start '%s': %s", processBuilder.command().get(0),
|
||||||
result.getMessage()));
|
result.getMessage()));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return launcher.start(processBuilder);
|
return launcher.start(processBuilder);
|
||||||
} finally {
|
} finally {
|
||||||
WindowsHandleFunctions.restoreStandardHandles(result);
|
WindowsHandleFunctions.restoreStandardHandles(result);
|
||||||
if (result.isFailed()) {
|
if (result.isFailed()) {
|
||||||
throw new NativeException(String.format("Could not restore process handles: %s", result.getMessage()));
|
throw new NativeException(String.format("Could not restore process handles: %s", result.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package net.rubygrapefruit.platform.internal.jni;
|
package net.rubygrapefruit.platform.internal.jni;
|
||||||
|
|
||||||
import net.rubygrapefruit.platform.internal.FunctionResult;
|
import net.rubygrapefruit.platform.internal.FunctionResult;
|
||||||
|
|
||||||
public class WindowsHandleFunctions {
|
public class WindowsHandleFunctions {
|
||||||
public static native void markStandardHandlesUninheritable(FunctionResult result);
|
public static native void markStandardHandlesUninheritable(FunctionResult result);
|
||||||
|
|
||||||
public static native void restoreStandardHandles(FunctionResult result);
|
public static native void restoreStandardHandles(FunctionResult result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user