I am developing a small application that executes shell commands and displays the output say for example ping command. The application has an edittext which takes the hostname or IP as input from user and a button to execute the command. For the time being I have used an ArrayList which stores the output generated after the execution of the command. But it is not a proper way to display the output, I would rather prefer to display the output dynamically like a standalone command line display which displays the output line by line on runtime. Is there any specific way to display the output during runtime.
The following is code
protected void executePingCommand() {
List<String> output=new ArrayList<String>();
output.clear();
try
{
Process pr=Runtime.getRuntime().exec(new String[]{"su","-c","ping -c 5 "+ipadd});
BufferedReader br=new BufferedReader(new InputStreamReader(pr.getInputStream()));
String var=null;
String temp=br.readLine();
while((var=br.readLine())!=null)
{
output.add(var);
display(output);
}
}
catch(Exception e)
{
}
}
protected void display(List<String> output2) {
// TODO Auto-generated method stub
pingOutput.setAdapter(new ArrayAdapter<String>(this, R.layout.custom_list_view, output2 ));
return;
}
Sounds like you need to setup a runnable that would execute with an onclicklistener. IE user types in the IP address, clicks button. It then refreshes your view to show the new item.