public boolean executer(String command, String logPath, String logFileErrorPath)throws Exception{
Fileutil fileutil = new Fileutil();
List<String> processList = new ArrayList<String>();
try{
Process process=Runtime.getRuntime().exec(command);
// 等待程序执行结束并输出状态
//错误输出流必须要读取防止在没有读取的时候将内存占满,程序假死
//将错误信息写入相关日志文件
new Thread(new Runnable() {
@Override
public void run() {
String line = null;
BufferedReader br = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
try {
logger.info("正在生成错误日志");
while ((line = br.readLine()) != null)
{
fileutil.genConfigFile(logFileErrorPath, line);
}
logger.info("生成错误日志结束");
br.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}).start();
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
StringBuilder logs = new StringBuilder();
int i = 0;
int k = 0;
//读取日志时,200行向页面发送一次
while ((line = br.readLine()) != null) {
processList.add(line);
*********
}
if (!command.contains(Constant.INSTALLWARSHELL))
{
new Thread(new Runnable() {
@Override
public void run() {
try {
logger.info("开始写入日志");
for (String line1:processList)
{
fileutil.genConfigFile(logPath, line1);
}
logger.info("日志写入结束");
}
catch (Exception e) {
e.printStackTrace();
}
}
}).start();
br.close();
}
int exitCode = process.waitFor();
if (exitCode == 0) {
return true;
}
}catch(Exception e){
e.printStackTrace();
}
return false;
}