DOSUtil
2024-10-07 10:54:18
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("文件内容为空");
}
}
}
最新文章
- ElasticSearch入门系列(五)数据
- office编程必不可少 [转]
- 启用PowerShell Web Access
- Android - Ashmem驱动
- Android实现自适应正方形GridView
- Python自然语言处理学习笔记之选择正确的特征(错误分析 error analysis)
- lumen 中的 .env 配置文件简介和适用场景
- Spark 1.6升级2.x防踩坑指南
- python 中的%s是什么意思呢?
- SuperVideo,一款直播,点播,投屏并有的app
- Up-to-date cache with EclipseLink and Oracle
- Hexo 搭建博客 本地运行 常见报错及解决办法
- leetcode-algorithms-18 4Sum
- MongoDB中空间数据的存储和操作
- 数组相同的key组成新的数组
- CentOS7 安装mysql(YUM方式)
- red ant
- hdu 3466 Proud Merchants 01背包变形
- cocos2d-x:初探TestLua
- Unity小知识---第三人称中设置摄像机的简单跟随
热门文章
- axios 拦截以及 API简单配置(element)
- 【Python】Visual Studio Code 安装&;&;使用 hello python~~~~
- Oracle删除表时候有外键 不能删除
- codeforces#1215E. Marbles(状压DP)
- 剑指offer--day11
- IDEA&;GIT应用
- DataTable clone()和copy()的区别
- [Web 前端] 019 css 定位之绝对定位与相对定位
- [Python3 练习] 004 水仙花数
- javascript自定义Map对象