Skip to content

Instantly share code, notes, and snippets.

@pandres95
Forked from anonymous/gist:5d99d534e480bd661ad6
Last active August 29, 2015 14:17
Show Gist options
  • Save pandres95/ee02588763e795aec18f to your computer and use it in GitHub Desktop.
Save pandres95/ee02588763e795aec18f to your computer and use it in GitHub Desktop.
package comando;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author maryuryjulieth
*/
public class Comando {
public static ArrayList<String[]> stream2String(InputStream is) throws IOException {
if (is != null) {
/*
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
is.close();
}
return writer.toString();
*/
ArrayList<String[]> res = new ArrayList<String[]>();
Scanner s = new Scanner(is);
while(s.hasNextLine()){
String[] line = s.nextLine().split("\t");
res.add(line);
}
return res;
} else {
return null;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
Process process = Runtime.getRuntime().exec("tracert -h 5 www.google.com");
InputStream is = process.getInputStream();
ArrayList<String[]> lineas = stream2String(is);
for(String[] linea: lineas){
System.out.println(linea[linea.length - 1]);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment