gpt4 book ai didi

java - 尝试终止任务时出现异常

转载 作者:行者123 更新时间:2023-11-29 07:51:50 26 4
gpt4 key购买 nike

在下面的代码中,我试图终止正在运行的 iTunes 进程。但我越来越异常(exception)。我缺少什么?

代码:

import java.io.IOException;

public class KillProcess {

public static void main(String[] args) throws IOException {
Runtime.getRuntime().exec("TASK KILL /F /IM itunes.exe");
}

}

异常:

Exception in thread "main" java.io.IOException: Cannot run program "TASK": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)

最佳答案

TASKKILL 之间不应有空格。它是 TASKKILL

Runtime.getRuntime().exec("TASKKILL /F /IM itunes.exe");

关于java - 尝试终止任务时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20582879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com