public class CommandUtil {
private static final String WINDOWS_NT = "Windows";
private static final String LINUX = "Linux";
public static boolean execute(String[] commands) {
boolean success = false;
Process proc = null;
try {
// osName = System.getProperty("os.name");
proc = Runtime.getRuntime().exec(commands);
BufferedReader bt = new BufferedReader(new InputStreamReader(
proc.getInputStream()));
String line = null;
while ((line = bt.readLine()) != null) {
System.out.println(line);
}
int exitVal = proc.waitFor();
if (exitVal == 0) {
success = true;
} else {
success = false;
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return success;
}
}调用控制台执行命令工具类
最新推荐文章于 2024-11-11 14:29:19 发布

1646

被折叠的 条评论
为什么被折叠?



