添加参数来调用Runtime.getRuntime()? [英] Adding parameters to Runtime.getRuntime()?
本文介绍了添加参数来调用Runtime.getRuntime()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无效restartWeb(){
尝试{
的String [] =命令,新的String [] {webRestarter.exe,>>中,webLog.log};
调用Runtime.getRuntime()EXEC(命令)。
}赶上(java.io.IOException异常错误){
webServer.logError(err.getMessage());
}
}
为什么不工作的呢?我怎么能修复它所以它的工作就像我希望它?
- 带有参数的执行webRestarter.exe >> webLog.log
所以它会吐出这样的:
webRestarter.exe>> webLog.log
解决方案
您根本无法在 EXEC
调用中使用的管道。管道的外壳的功能,而不是操作系统。因此,我们必须调用shell可执行文件,并通过命令。试试这个:
的String [] =命令,新的String [] {cmd.exe的,/ C,启动webRestarter.exe,>>中,博客。登录};
void restartWeb() {
try {
String[] command = new String[] {"webRestarter.exe" , ">>","webLog.log"};
Runtime.getRuntime().exec(command);
} catch (java.io.IOException err) {
webServer.logError(err.getMessage());
}
}
Why doesn't this work? How could I fix it so it does work like I want it to?
-- Executes webRestarter.exe with parameters >>webLog.log
So it'd spit out something like this:
webRestarter.exe>>webLog.log
解决方案
You simply can't use pipes in a exec
call. Pipes are a functionality of the shell and not of the operating system. So we have to call the shell executable and pass the command. Try this instead:
String[] command = new String[] {"cmd.exe", "/c", "start webRestarter.exe", ">>","webLog.log"};
这篇关于添加参数来调用Runtime.getRuntime()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文