首页 > 其他 > 详细

DOSUtil

时间:2019-08-15 01:00:56      阅读:80      评论:0      收藏:0      [点我收藏+]

package TestLinkPackage;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

public class DOSUtil
{
private Process process;
private File workspaceFile;
private File dirFile;
private File buildXMLDirectory;
private String workspacePath;
private String buildXMLDirectoryPath;
private String antCommand;

public void RunDOS()
{
this.workspaceFile = new File("");
this.workspacePath = this.workspaceFile.getAbsolutePath();

this.dirFile = new File(this.workspacePath);

File[] files = this.dirFile.listFiles();

this.buildXMLDirectoryPath = (this.workspacePath + "\\BuildXML");

this.buildXMLDirectory = new File(this.buildXMLDirectoryPath);

File[] xmlFiles = this.buildXMLDirectory.listFiles();

this.antCommand = ("cmd.exe /c ant -buildfile " + this.buildXMLDirectoryPath + "\\build.xml");
if (files.length != 0)
{
File[] arrayOfFile1;
int j = (arrayOfFile1 = files).length;
for (int i = 0; i < j; i++)
{
File file = arrayOfFile1[i];
if (file.getName().equals("BuildXML")) {
if (xmlFiles.length != 0)
{
File[] arrayOfFile2;
int m = (arrayOfFile2 = xmlFiles).length;
for (int k = 0; k < m; k++)
{
File xmlfile = arrayOfFile2[k];
if (xmlfile.getName().equals("build.xml")) {
try
{
this.process = Runtime.getRuntime().exec(this.antCommand);
InputStream iStream = this.process.getInputStream();
BufferedReader bReader = new BufferedReader(new InputStreamReader(iStream));
String str = null;
while ((str = bReader.readLine()) != null) {
System.out.println(str);
}
System.out.println("我已经执行了");
}
catch (IOException e)
{
e.printStackTrace();

continue;
}
} else {
System.out.println("build.xml文件不存在");
}
}
}
else
{
System.out.println("BuildXML文件夹为空");
}
}
}
}
else
{
System.out.println("文件夹内容为空");
}
}
}

DOSUtil

原文:https://www.cnblogs.com/xxsl/p/11355507.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!