1   package eu.fbk.dkm.pikes.tintop.util;
2   
3   import org.apache.log4j.Logger;
4   
5   import java.io.BufferedReader;
6   import java.io.File;
7   import java.io.IOException;
8   import java.io.InputStreamReader;
9   import java.util.ArrayList;
10  import java.util.Arrays;
11  
12  /**
13   * Created by alessio on 16/03/15.
14   */
15  
16  public class GenericCommandLine {
17  
18  	static Logger logger = Logger.getLogger(GenericCommandLine.class.getName());
19  
20  	public static ArrayList<String> genericRun(String baseDir, String... command) throws IOException, InterruptedException {
21  		logger.debug(Arrays.toString(command));
22  
23  		ArrayList<String> ret = new ArrayList<>();
24  
25  		ProcessBuilder pb = new ProcessBuilder(command);
26  		pb.directory(new File(baseDir));
27  		final Process p = pb.start();
28  
29  		String line;
30  
31  		BufferedReader bri = new BufferedReader
32  				(new InputStreamReader(p.getInputStream()));
33  		while ((line = bri.readLine()) != null) {
34  			ret.add(line);
35  		}
36  		bri.close();
37  
38  		p.waitFor();
39  
40  		return ret;
41  	}
42  
43  
44  }