您的位置:首页 > 运维架构 > Shell

linux中java调用shell脚本

2016-02-25 15:43 746 查看
全部代码

------------------------------------------------------------------------------------------------------------------------------

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.LineNumberReader;

public class RunShell {

public static void main(String[] args) {

try {

Process process = Runtime.getRuntime().exec("shell绝对路径/shell名称 参数1 参数2");

InputStreamReader ir = new InputStreamReader(process.getInputStream());

LineNumberReader input = new LineNumberReader(ir);

String line;

while((line = input.readLine()) != null)

System.out.println(line);

input.close();

ir.close();

} catch (IOException e) {

// TODO: handle exception

e.printStackTrace();

}

}

}

转自:http://blog.csdn.net/heyetina/article/details/6555746
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: