Execute "show channels" command using Java

Very new to Asterisk! Trying to write a JAVA program to execute the “show channels” command!!

Can someone please help!

[code]import java.io.IOException;
import net.sf.asterisk.manager.AuthenticationFailedException;
import net.sf.asterisk.manager.ManagerConnection;
import net.sf.asterisk.manager.ManagerConnectionFactory;
import net.sf.asterisk.manager.TimeoutException;
import net.sf.asterisk.manager.action.OriginateAction;
import net.sf.asterisk.manager.response.ManagerResponse;
import net.sf.asterisk.manager.event.;
import net.sf.asterisk.manager.
;
import net.sf.asterisk.manager.action.CommandAction;

public class Event {

private DefaultManagerConnection dmc;

public Event() throws IOException {
}


public void run() throws IOException, AuthenticationFailedException,TimeoutException {
    
    DefaultManagerConnection dmc = new DefaultManagerConnection();
    dmc.setUsername("xxxxxxx");
    dmc.setPassword("pass");
    dmc.setHostname("xx.xx.xxx.xxx");
    
    dmc.login();
    dmc.addEventHandler(new ManagerEventHandler() {
        public void handleEvent(ManagerEvent event) {
            System.out.println( event );
        }
    });
    
    CommandAction t = new CommandAction();
    t.setCommand("show channels");
    dmc.sendAction(t);
    
    
    try {
        Thread.sleep(3000);
    } catch ( Exception e ) {}
    
    
    dmc.logoff();
}

public static void main(String[] args) throws Exception {
    Event Event;
    Event = new Event();
    Event.run();
}

}[/code]

... CommandResponse r = (CommandResponse) dmc.sendAction(t); Iterator i = r.getResult().iterator(); while (i.hasNext()) { System.out.println(i.next()); }

But again, as I already said at http://forums.digium.com/viewtopic.php?t=8142: use the StatusAction instead, it saves you lots of trouble parsing command line output!