linux中java调用shell脚本

来源:互联网 发布:linux审计日志分析 编辑:程序博客网 时间:2024/06/02 08:40

全部代码

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

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
0 0