传入动态目录
public void updateApprovalSh(String tempName) {
try {
String cmd = "mv " + filepathaudit +File.separator+ tempName+".xlsx" + " " + filepath;
log.info("开始执行命令:" + cmd);
Process process = Runtime.getRuntime().exec(cmd);
try (PrintWriter printWriter =
new PrintWriter(
new BufferedWriter(new OutputStreamWriter(process.getOutputStream())), true);
BufferedReader read =
new BufferedReader(new InputStreamReader(process.getInputStream()))) {
printWriter.println("cd " + filepath);
printWriter.println(cmd);
printWriter.println("exit");
String line;
while ((line = read.readLine()) != null) {
log.info(line);
}
}
log.info(
cmd
+ " 执行状态:"
+ process.waitFor()
+ " 执行时间:"
+ DateUtils.getStringDate2(new Date()));
} catch (Exception e) {
log.error("", e);
throw new ShellRunException(
"服务器运行Shell出错! " + DateUtils.getStringDate2(new Date()));
}
}
|