package com.mx.dla.dda.general.utilerias;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class ProcesosUtilerias {

	public static ShellResponseDTO ejecutaShell(String[] pstComando) throws IOException {
		String s = null;
		ShellResponseDTO response = new ShellResponseDTO();
		ArrayList<String> outputs = new ArrayList<String>();
		ArrayList<String> errors = new ArrayList<String>();

		Process p = Runtime.getRuntime().exec(pstComando);

		BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
		BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

		while ((s = stdInput.readLine()) != null)
			outputs.add(s);

		while ((s = stdError.readLine()) != null)
			errors.add(s);

		response.setErrorData(outputs);
		response.setOutputData(errors);

		return response;
	}

}
