我是靠谱客的博主 小巧大地,这篇文章主要介绍java执行shell封装,解决java运行shell卡顿,堵塞问题,现在分享给大家,希望可以做个参考。


public class ShellUtils {
    
    public static String line = null;
    // 脚本执行
    public static void shellScripts(String filePath){
        try {
            Process p0 = Runtime.getRuntime().exec(filePath);
            //读取标准输出流  
            BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(p0.getInputStream()));
            while ((line=bufferedReader.readLine()) != null) {
                System.out.println(line);
            }
            //读取标准错误流  
            BufferedReader brError = new BufferedReader(new InputStreamReader(p0.getErrorStream(), "gb2312"));
            String errline = null;
            while ((errline = brError.readLine()) != null) {
                System.out.println(errline);
            }
            //waitFor()判断Process进程是否终止,通过返回值判断是否正常终止。0代表正常终止  
            int c=p0.waitFor();
            if(c!=0){
            }
        } catch (IOException | InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

最后

以上就是小巧大地最近收集整理的关于java执行shell封装,解决java运行shell卡顿,堵塞问题的全部内容,更多相关java执行shell封装内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(154)

评论列表共有 0 条评论

立即
投稿
返回
顶部