java kill task,无法从Java进程使用taskkill.exe

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?

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值