The Ant telnet task doesn't support failing early if something goes wrong. What I wanted to do was run a script on a remote server, which finishes with "ok" if everything worked and "failed" if not. The remote script could take some time, which is why waiting for "ok" with a timeout wasn't quite good enough. I've added code to TelnetTask which allows a new "failon" attribute for <read> elements. If the text in the attribute is read from the connection, the task fails. I use this to stop a build if deployment to a remote container fails. I'll attach the patch (cvs -q diff -u) after creating the bug.
Created attachment 5861 [details] Patch to add failon attribute to telnet's read task.