java执行.bat/.sh脚本 实例

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_31565213/article/details/78900803
private static String exec(String script){
		Runtime r = Runtime.getRuntime();
		InputStream is =null;
		InputStreamReader ir = null;
		BufferedReader br =null;
		String output = "";
		try {
			Process p = r.exec(script);
			is = p.getInputStream();
			ir = new InputStreamReader(is);
			br = new BufferedReader(ir);
			output += br.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				if (null != br) {
					br.close();
				}
				if (null != ir) {
					ir.close();
				}
				if (null != is) {
					is.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return output;
	}

可在脚本中输出相关信息做业务逻辑判断。直接复制粘贴即可。
展开阅读全文

没有更多推荐了,返回首页