Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: run on windows #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/com/xiaoju/basetech/util/CmdExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ public class CmdExecutor {
private static final Logger LOG = LoggerFactory.getLogger(CmdExecutor.class);

private static AtomicInteger counter = new AtomicInteger(0);
private static String osName=System.getProperty("os.name").toLowerCase();

private static int maxThread = 64;

private static ThreadPoolExecutor executor = new ThreadPoolExecutor(20, maxThread, 5 * 60, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(1), r -> new Thread(r, "CmdThread-" + counter.getAndIncrement()));

private static boolean isWindows(){
return osName.contains("windows")? true:false;
}
public static int executeCmd(String[] commands, Long timeout) throws Exception {
StringBuffer ret = new StringBuffer();
if (commands == null || commands.length == 0) {
Expand All @@ -46,7 +50,8 @@ public static int executeCmd(String[] commands, Long timeout) throws Exception {
}

LOG.info("executeCmd : bash -c " + e.toString());
ProcessBuilder var12 = new ProcessBuilder(new String[]{"bash", "-c", e.toString()});
String []cmd=isWindows()? new String[]{"cmd", "/c", e.toString()} : new String[]{"bash", "-c", e.toString()};
ProcessBuilder var12 = new ProcessBuilder(cmd);
var12.redirectErrorStream(true);
process = var12.start();
CmdExecutor.ReadLine readLine = new CmdExecutor.ReadLine(process.getInputStream(), ret, true);
Expand Down