本文介绍了无法从Java进程使用taskkill.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过集成测试杀死Windows(Windows XP 32位)上的外部进程.我以为我只会使用'taskkill.exe',但似乎无法正常工作.基本上,每次我从Java启动"taskkill.exe"进程时,它都会返回退出值-1073741515,但不会向标准错误/输出显示任何内容.

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());
}

更多数据点:

  • -1073741515显然意味着应用程序无法正确初始化".虽然对我不是很有帮助;)
  • 我尝试了很多taskkill.exe参数的组合;我试过在命令前加上'cmd','/c'.症状完全相同
  • 我尝试执行Windows \ system32下的其他Windows程序,但我也得到-10737 ...
  • 执行"dir"或"echo"之类的方法可以正常工作.

任何提示可能是什么问题?

Any hints on what might be the problem?

推荐答案

您是否尝试过以其他用户身份执行应用程序?如果您在Windows中使用纯批处理文件运行应用程序,请右键单击并选择Run as administrator并查看结果.您运行的帐户可能没有足够的权限来执行本机应用程序.

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.

这篇关于无法从Java进程使用taskkill.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:28