unable to use taskkill.exe from a java process

旧城冷巷雨未停 提交于 2019-12-11 03:08:12

问题


I need to kill an external process on windows (WindowsXP 32bit) from my integration test. I thought I'd just use 'taskkill.exe' but I cannot seem to get it working. Basically, every time I kick off a 'taskkill.exe' process from java it returns exit value -1073741515, nothing is printed to std error/output.

To reproduce the problem I wrote this simple application:

public static void main(String[] args) throws Exception {
    ProcessBuilder builder = new ProcessBuilder();
    //In my real code, I kill process by its pid. However below also shows the problem:
    builder.command("taskkill.exe", "/?");
    builder.redirectErrorStream(true);
    Process p = builder.start();
    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = r.readLine();
    System.out.println("out:");
    while(line != null) {
        System.out.println(line);
        line = r.readLine();
    }
    System.out.println(p.waitFor());
}

More data points:

  • -1073741515 apparently means "The application failed to initialize properly". Not very helpful for me though ;)
  • I've tried bunch of combinations of taskkill.exe parameters; I've tried prefixing the command with 'cmd', '/c'. Symptoms are exactly the same
  • I tried executing other windows programs that live under windows\system32 and I also get -10737...
  • Executing things like 'dir' or 'echo' works ok.

Any hints on what might be the problem?


回答1:


Have you tried executing your application as a different user? If you're running your app with a plain batch file in windows, right click and select Run as administrator and see the results. It's likely the account you're running under doesn't have enough rights to execute native apps.



来源:https://stackoverflow.com/questions/12534659/unable-to-use-taskkill-exe-from-a-java-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!