package Testlink;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; /*
* 此方法主要是用于执行DOS命令
*/
public class DOSUtil { // 定义执行的进程
private Process process; // 定义工作目录
private File workspaceFile; // 定义工作目录下的所有文件和文件夹
private File dirFile; // 定义buildXML文件夹
private File buildXMLDirectory; // 工作目录路径
private String workspacePath; // build.xml文件路径
private String buildXMLDirectoryPath; // ant执行build.xml文件
private String antCommand; /**
* 该方法主要用于执行ANT的build.xml文件
*/
public void RunDOS() {
// 获取当前地址的路径
workspaceFile = new File("");
workspacePath = workspaceFile.getAbsolutePath(); // 获取路径下的所有文件
dirFile = new File(workspacePath);
File[] files = dirFile.listFiles(); // 获取BuildXML文件夹的路径
buildXMLDirectoryPath = (workspacePath + "\\BuildXML"); // 获取BuildXML文件下的所有文件
buildXMLDirectory = new File(buildXMLDirectoryPath);
File[] xmlFiles = buildXMLDirectory.listFiles(); // 定义需要执行的ant命令
antCommand = ("cmd.exe /c ant -buildfile " + this.buildXMLDirectoryPath + "\\build.xml"); // 判断工作目录是否为空,如果不为空就向下执行
if (files.length != 0) {
// 循环遍历是否存在BuildXML文件夹
File[] arrayOfFile1;
int j = (arrayOfFile1 = files).length;
for (int i = 0; i < j; i++) {
File file = arrayOfFile1[i];
if (file.getName().equals("BuildXML")) {
// 判断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 {
process = Runtime.getRuntime().exec(antCommand);
InputStream iStream = 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();
}
} else {
System.out.println("build.xml文件不存在");
}
}
} else {
System.out.println("BuildXML文件夹为空");
}
}
}
} else {
System.out.println("文件内容为空");
}
}
}

最新文章

  1. ElasticSearch入门系列(五)数据
  2. office编程必不可少 [转]
  3. 启用PowerShell Web Access
  4. Android - Ashmem驱动
  5. Android实现自适应正方形GridView
  6. Python自然语言处理学习笔记之选择正确的特征(错误分析 error analysis)
  7. lumen 中的 .env 配置文件简介和适用场景
  8. Spark 1.6升级2.x防踩坑指南
  9. python 中的%s是什么意思呢?
  10. SuperVideo,一款直播,点播,投屏并有的app
  11. Up-to-date cache with EclipseLink and Oracle
  12. Hexo 搭建博客 本地运行 常见报错及解决办法
  13. leetcode-algorithms-18 4Sum
  14. MongoDB中空间数据的存储和操作
  15. 数组相同的key组成新的数组
  16. CentOS7 安装mysql(YUM方式)
  17. red ant
  18. hdu 3466 Proud Merchants 01背包变形
  19. cocos2d-x:初探TestLua
  20. Unity小知识---第三人称中设置摄像机的简单跟随

热门文章

  1. axios 拦截以及 API简单配置(element)
  2. 【Python】Visual Studio Code 安装&amp;&amp;使用 hello python~~~~
  3. Oracle删除表时候有外键 不能删除
  4. codeforces#1215E. Marbles(状压DP)
  5. 剑指offer--day11
  6. IDEA&amp;GIT应用
  7. DataTable clone()和copy()的区别
  8. [Web 前端] 019 css 定位之绝对定位与相对定位
  9. [Python3 练习] 004 水仙花数
  10. javascript自定义Map对象