java调用shell的一段代码
2013-07-15 16:48
295 查看
private final static String FILL_EVENT_SCRIPT = "/opt/soft/kettle/run/run_report.sh"; //shell脚本的路径位置
private void processEvent(String reportName, String context) throws Exception {
logger.info("reportName: " + reportName + " | context: " + context);
File f = new File(FILL_EVENT_SCRIPT);
if (f.exists()) {
String[] cmd = { FILL_EVENT_SCRIPT, "-c", reportName, context};
Process process = Runtime.getRuntime().exec(cmd);
InputStreamReader ir = new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line = null;
process.waitFor();
while ((line = input.readLine()) != null) {
logger.info(line);
}
if (ir != null) {
ir.close();
}
if (input != null) {
input.close();
}
} else {
logger.info("file is not exists");
}
}
private void processEvent(String reportName, String context) throws Exception {
logger.info("reportName: " + reportName + " | context: " + context);
File f = new File(FILL_EVENT_SCRIPT);
if (f.exists()) {
String[] cmd = { FILL_EVENT_SCRIPT, "-c", reportName, context};
Process process = Runtime.getRuntime().exec(cmd);
InputStreamReader ir = new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line = null;
process.waitFor();
while ((line = input.readLine()) != null) {
logger.info(line);
}
if (ir != null) {
ir.close();
}
if (input != null) {
input.close();
}
} else {
logger.info("file is not exists");
}
}
相关文章推荐
- java代码中执行shell或调用系统命令
- Java代码中调用shell脚本和python脚本并获得输出结果(分为小数据量和大数据量)
- Java代码调用Shell脚本并传入参数实现DB2数据库表导出到文件
- android jni开发 把一段java代码转换成c++方式调用
- 怎样在java代码中调用执行shell脚本
- Java代码调用Shell脚本并传入参数实现DB2数据库表导出到文件
- 重复调用ab命令的shell代码和整理ab结果的java代码
- android jni开发 把一段java代码转换成c++方式调用
- 分享一段JNI子线程中调用Java静态方法的代码
- Java 通过JNI调用C或者CPP代码
- android111 java中调用c代码
- JNI NDK (AndroidStudio+CMake )实现Java调用C C++代码流程
- 润乾报表在websphere8部署配置数据源报错 java.sql.SQLException: 调用中无效的参数DSRA0010E: SQL 状态 = null,错误代码 = 17,433 而失败
- Unity3D调用Android Java代码
- flex4 RemoteObject 动态调用 java 代码
- 在java后台用javacript写一段小代码实现html页面颜色的自动改变
- kettle+java代码调用Webservice
- java 调用shell命令
- solr4.2 JAVA调用代码
- java本地调用cmd,shell命令,远程调用Linux执行命令方法总结