Java API

Hi all, I’m new to RouterOS API. Right know, I’ve been able to log in to the router from api, as I can see in the router’s logs, I’m trying to test running a command:

/log/print

How can I get the results of the command? Is there a way to send the output to a .txt file or something. I just want to test if the connection works, I tried adding a new user but it’s not working.

Any help is really appreciated! Thanks.

Can you give the actual Java code you’re using?

public static void main(String args) {
ApiConn ret = new ApiConn(“172.16.100.1”, 8728);

if (!ret.isConnected()) {

ret.start();
try {
ret.join();
if (ret.isConnected()) {

ret.login(“prueba”, new char[0]);

}
}
catch (InterruptedException ex) {
//Logger.getLogger(T3apiView.class.getName()).log(Level.SEVERE, null, ex);
//return null;
System.out.println(ex);
}
}
String ip;
ip = ret.sendCommand(“/log/print”);
System.out.println(ip);

}}

This is my main, and I’m using the libAPI.jar

This is all for testing purposes. Variable ip shows the message “Sent successfully”, so I guess it means the command was sent successfully.

Looking at the examples, the getData() method can give you the next response. You need to keep calling this method for each log entry, until you get a “!done” response.

So for example, just to print the first log entry:

ip = ret.sendCommand("/log/print");
 System.out.println(ip);
Syste.out.println(ret.getData());

Thank you so much!