java调用机器上的shell脚本

时间:2022-11-28 10:51:37

java调用机器上的shell脚本,可以这样方便的通过shell脚本调用本机的C、C++等程序

Process process = null;
Runtime runTime = Runtime.getRuntime();
String shellCmd = "sh xxxxxxxxxxx.sh ";
String shellPath = getSoLibPath();
logger.info("执行shell命令:" + shellCmd);
long startTime = System.currentTimeMillis();
process = runTime.exec(shellCmd, null, new File(shellPath));
int resultCode = process.waitFor();
long endTime = System.currentTimeMillis();
logger.info("耗时=" + (endTime - startTime) + "毫秒");