正文

JAVA执行Linux脚本问题2012-05-04 12:43:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lovebugs/53456.html

分享到:

在项目中需要修改Linux主机信息,于是用了Linux支持的命令来完成操作。

 

该命令为  /bin/sed -i '1,$'d   /var/log/XX.log

 

调用方法为:

public static InputStream excute(String command) {
    InputStream inputStream = null;
    System.out.println(command);
    try{
     Process process = Runtime.getRuntime().exec(command);
      inputStream = process.getInputStream();
      BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
      System.out.println(br.readLine());
    }catch(Exception e){
     e.printStackTrace();
    }
    return inputStream;
   }

发现根本就为清空该log文件。调试了半天不知道什么原因。

我于是在主机上自己新建了一个 shell脚本rmfilecontent  该脚本中写了/bin/sed -i '1,$'d   /var/log/XX.log

 

在调用 excute("rmfilecontent ")。It  works! 

 

阅读(3789) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册