java执行linux下脚本命令

java执行linux下脚本命令

 

		String str = input.getString(0);
		logger.info("request data:"+str);
		try {
			String[] command = { "/bin/sh", "-c", str };
			Process ps = Runtime.getRuntime().exec(command);
			BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
			StringBuffer sb = new StringBuffer();
			String line;
			while ((line = br.readLine()) != null) {
				sb.append(line);
			}
			String result = sb.toString();
			int i=result.indexOf("{");
			if(i!=-1){
				logger.error(result.substring(i));
			}
		} catch (IOException e) {
			logger.error("execute(Tuple, BasicOutputCollector)", e);
			e.printStackTrace();
		}
	

 

posted @ 2016-08-01 17:18  W&L  阅读(300)  评论(0编辑  收藏  举报