wget命令
e:\wget -r -c --limit-rate=1M -t 10 -T 60 -o d:\wgetlog\result.txt -O E:\projectTest/rhq-agent-update.log http://xxxx:8280/../opt/app/install/rhq-agent-update.log
程序关键代码
String cmd = wgetPath+"\\wget -r -c --limit-rate=1M -t 10 -T "+timeoutms+" -o " + logPath + " -O " + filePath + " " + url;
Process download=Runtime.getRuntime().exec(cmd);
download.waitFor();
new Thread () {
public void run() {
logger.info("start resultFile monitor!");
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader reader = null;;
try {
reader = new BufferedReader(new FileReader(logFile));
while(true) {
String line = reader.readLine();
if (line != null) {
logger.debug(line);
} else {
break;
}
}
break;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (reader != null)
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
validateFile();
}
public void validateFile() {
File download = new File(filePath);
try {
if(download.length() > 0) {
DownloadXMLConfig.setFileStatus(verNum,fileName, "download");
}else{
DownloadXMLConfig.setFileStatus(verNum,fileName, "fail");
if (download.exists()) {
download.delete();
}
}
} catch (Exception e) {
// TODO: handle exception
logger.error("DownloadXMLConfig setFileStatus exception : "+e);
}
}
}.start();