-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can ProcessBuilder be used to run sendctrlc.exe? #55
Comments
@oleg-nenashev @stephanreiter Any thoughts? I would appreciate your feedback. |
Sorry, missed the previous notification. |
Using ProcessBuild is no problem. Good idea! Less native code ... |
@oleg-nenashev Thanks. I meant something like public static boolean sendCtrlC(int pid) {
Process process = new ProcessBuilder("sendctrlc.exe", pid).start();
return waitFor(process, 5000) != null;
}
@Nullable
private static Integer waitFor(@NotNull Process process, int timeoutMillis) {
long stop = System.currentTimeMillis() + timeoutMillis;
while (System.currentTimeMillis() < stop) {
try {
Thread.sleep(100);
return process.exitValue();
}
catch (Exception ignore) {
}
}
return null;
} This way, ProcessBuilder is not exposed in winp's API, so it can be changed without breaking changes too. |
Will that terminate the sendctrl.exe process after 5secs? That shouldn't be left lingering. |
Same should be (made) true for the native code! :) |
Oops, |
I don't know much about ProcessBuilder anymore. :) And sendctrlc.exe will first detach from its console, then attach to the process to avoid what you describe w.r.t. the parent process.
|
@stephanreiter Sorry for not being clear. Yes, |
Ah, now I understand. Well, then the Ctrl+C will go to the parent as well. I guess that should be documented to make it obvious. |
…nkinsci#60, jenkinsci#55) Additionally, diagnostics is improved by capturing output stream.
Currently, sendctrlc.exe is spawned in winp.cpp.
Is it possible to use java.lang.ProcessBuilder to spawn sendctrlc.exe and, thus, simplify code?
If no, it'd be great to write a comment in code explaining decision.
The text was updated successfully, but these errors were encountered: