30 lines
1.0 KiB
Java
30 lines
1.0 KiB
Java
|
|
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;
|
||
|
|
}
|
||
|
|
}
|