public static void executeWithoutResult(String shellFile)
{
//脚本文件为NULL或空值
if (null == shellFile || shellFile.equals(""))
{
logger.warn("ShellCommand shellFile is null.");
return;
}
if (logger.isDebugEnabled())
{
logger.debug("bash " + shellFile);
}
try
{
Runtime.getRuntime().exec("bash " + shellFile);
}
catch (Exception e)
{
logger.error("Execute " + shellFile + " exception:", e);
}
}
ShellCommand_Java代码中执行shell脚本_Process的输入、输出、错误流都需要关闭(3)
最新推荐文章于 2022-08-05 20:46:01 发布
本文介绍了一个简单的Java方法,用于执行Shell脚本文件且不返回执行结果。该方法首先检查传入的脚本文件是否为空或null,然后通过Runtime类的exec方法执行脚本。此外,还使用了日志记录来报告执行过程中的调试信息及异常。
535

被折叠的 条评论
为什么被折叠?



