重点是Runtime.getRuntime().exec()函数
package com.goodwill.hdr.utils;
import com.goodwill.core.utils.PropertiesUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* java 调用SSIS
* SSISCaller
*
* @author gaoyapeng
* @version 1.0, Created on 2020-01-08
*/
public class SSISCaller {
private static final Logger logger = LoggerFactory.getLogger(SSISCaller.class);
public static boolean excuteCube(String type) throws IOException, InterruptedException {
String path = PropertiesUtils.getPropertyValue("config.properties", "ssis.file.path");
if (StringUtils.isNotBlank(type)) {
if ("sealUp_gh".equals(type)) {
path = PropertiesUtils.getPropertyValue("config.properties", "ssis.file.report.path");
}
}
// create the execution process
Process executionProcess = Runtime.getRuntime().exec("dtexec /f \"" + path + "\"");//这个地方要写你做好的dtsx文件的路径
// create the output reader
BufferedReader output = new BufferedReader(new InputStreamReader(new DataInputStream(
executionProcess.getInputStream())));
String readStr;
while ((readStr = output.readLine()) != null) {
logger.info(readStr);
}
output.close();
// wait for the process to terminate
executionProcess.waitFor();
// check the exit value
if (executionProcess.exitValue() == 0) {
return true;
} else {
return false;
}
}
// end of main
}