gpt4 book ai didi

java - 向 Runtime.getRuntime() 添加参数?

转载 作者:行者123 更新时间:2023-11-29 06:46:51 25 4
gpt4 key购买 nike

void restartWeb() {
try {
String[] command = new String[] {"webRestarter.exe" , ">>","webLog.log"};
Runtime.getRuntime().exec(command);
} catch (java.io.IOException err) {
webServer.logError(err.getMessage());
}
}

为什么这行不通?我怎样才能修复它,让它像我想要的那样工作?

-- 使用参数执行 webRestarter.exe >>webLog.log

所以它会吐出这样的东西:

webRestarter.exe>>webLog.log

最佳答案

您根本不能在 exec 调用中使用管道。管道是 shell 而不是操作系统的功能。所以我们必须调用 shell 可执行文件并传递命令。试试这个:

String[] command = new String[] {"cmd.exe", "/c", "start webRestarter.exe", ">>","webLog.log"};

关于java - 向 Runtime.getRuntime() 添加参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3608944/

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