fix: 调整 playbook 执行日志记录
This commit is contained in:
30
src/main/java/net/geedge/api/util/CommandExec.java
Normal file
30
src/main/java/net/geedge/api/util/CommandExec.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package net.geedge.api.util;
|
||||
|
||||
import net.geedge.common.T;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandExec {
|
||||
|
||||
private File logFile;
|
||||
|
||||
public String exec(List<String> command) {
|
||||
String str = T.RuntimeUtil.execForStr(T.CharsetUtil.CHARSET_UTF_8, command.stream().toArray(String[]::new));
|
||||
if (logFile != null) {
|
||||
T.FileUtil.appendString(T.StrUtil.concat(true, "$ ", command.stream().collect(Collectors.joining(" ")), "\n"), this.logFile, "UTF-8");
|
||||
T.FileUtil.appendString(T.StrUtil.concat(true, str.stripTrailing(), "\n"), this.logFile, "UTF-8");
|
||||
}
|
||||
return str.stripTrailing();
|
||||
}
|
||||
|
||||
public Process execForProcess(List<String> command) {
|
||||
Process process = T.RuntimeUtil.exec(command.stream().toArray(String[]::new));
|
||||
return process;
|
||||
}
|
||||
|
||||
public CommandExec(File logFile ) {
|
||||
this.logFile = logFile;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user