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("文件夹内容为空");
}
}
}
原文:https://www.cnblogs.com/xxsl/p/11355507.html