This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
appsketch-works-device-api/src/main/java/net/geedge/api/util/CommandExec.java

30 lines
1.0 KiB
Java
Raw Normal View History

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;
}
}