首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java实施shell脚本

2012-11-09 
java执行shell脚本?public static void main(String[] args) throws Exception{String[] cmds new Strin

java执行shell脚本

?

public static void main(String[] args) throws Exception{               String[] cmds = new String[] { "/bin/sh", "-c","/usr/java/tomcat/bin/a.sh" };Process process = null;try {process = Runtime.getRuntime().exec(cmds, null, null);InputStreamReader ir = new InputStreamReader(process.getInputStream());LineNumberReader input = new LineNumberReader(ir);String line;process.waitFor();while ((line = input.readLine()) != null) {System.out.println(line);}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{process.destroy();}        }
?

?

热点排行