You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2002/08/11 22:12:52 UTC

DO NOT REPLY [Bug 11620] New: - TelnetTask: AntTelnetClient.waitForString(String, Integer) cannot pick a pattern string from a big output

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11620>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11620

TelnetTask: AntTelnetClient.waitForString(String, Integer) cannot pick a pattern string from a big output

           Summary: TelnetTask: AntTelnetClient.waitForString(String,
                    Integer) cannot pick a pattern string from a big output
           Product: Ant
           Version: 1.5
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Optional Tasks
        AssignedTo: ant-dev@jakarta.apache.org
        ReportedBy: orientphoebus@yahoo.com


When I use telnet task to read a string from a big output, like: tail -f XXX.log,

The read sub task 
could not found the string I am looking for, although it's in the output.

On the other hand. Ant only 
log the out put after it found the string pattern, usually, people like to see the telnet output in 
the process, the performance here is not critical.

Here I attached the code I made the change for 
solving these 2 problems:
        public void waitForString(String s, Integer timeout) {
            InputStream 
is = this.getInputStream();
            try {
                StringBuffer sb = new StringBuffer(1024);
                if (timeout == null 
|| timeout.intValue() == 0) {
                    while (sb.toString().indexOf(s) == -1){
			    char cc = (char) 
is.read();
			    if(cc=='\n'||cc=='\r'){
				if(!sb.toString().trim().equals(""))
	        		        
log(sb.toString(), Project.MSG_INFO);
				sb.delete(0,sb.length());
			    }
			    else
				sb.append(cc);
                    }
                } 
else {
                    Calendar endTime = Calendar.getInstance();
                    endTime.add(Calendar.SECOND, 
timeout.intValue());
                    while (sb.toString().indexOf(s) == -1) {
                        while 
(Calendar.getInstance().before(endTime) &&
                        is.available() == 0) {
                            Thread.sleep(250);
                        }
                        if 
(is.available() == 0) {
                            throw new BuildException(
                                "Response timed-out waiting for \""+s+'\"',
                                
getLocation());
                        }
			    char cc = (char) is.read();
			    if(cc=='\n'||cc=='\r' && 
sb.length()>0){
				if(!sb.toString().trim().equals(""))
	        		        log(sb.toString(), 
Project.MSG_INFO);
				sb.delete(0,sb.length());
			    }
			    else
				sb.append(cc);
                    }
                }
                log(sb.toString(), 
Project.MSG_INFO);
            } catch (BuildException be) {
                throw be;
            } catch (Exception e) {
                throw new 
BuildException(e, getLocation());
            }
        }

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>