ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 16562] New: - Can not accept characters from keyboard in a thread under ant java task
Date Wed, 29 Jan 2003 21:42:19 GMT
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=16562>.
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=16562

Can not accept characters  from keyboard in a thread  under ant java task

           Summary: Can not accept characters  from keyboard in a thread
                    under ant java task
           Product: Ant
           Version: 1.5.1
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Blocker
          Priority: Other
         Component: Core tasks
        AssignedTo: ant-dev@jakarta.apache.org
        ReportedBy: agrinbrg@yahoo.com


I have two classes one of them runs thread which is accepting data from 
keyboard.
Everything is going fine if I run my program in cmd window (Windows XP) like  
c:\> java A , where A is name of class with main method. I can accept symbols 
from keyboard in my thread. As soon as I run same program using ant, there is 
no respond from my program. It seems to me either there is something I need to 
add to "java" task as a parameter or something is wrong with ant.
 I also tried to run batch file from ant environment, but it did not help me.


Below you can find my test classes both batch file as well as  build file.

Sinserely, 
Aleksandr Grinberg
agrinbrg@yahoo.com


///////////////////////////////////////////////////////////////////////
// class with main method
import java.io.*;

class A{

public static void main(String[] args) 
{
 	String f="1234 ";
	String x=" ";
String empty="";
 
	System.out.println (" emty string " + empty.trim().length());
	System.out.println ("f.indexof(x) " +f.indexOf(x) );
	System.out.println(" f.substring(f.indexof(x) " + f.substring(f.indexOf
(x)));
	System.out.println(" f.substring(f.indexof(x).length() " 
           + f.substring(f.indexOf(x)).length()
		);


	Console console = new Console();
	console.start();

}
}
///////////////////////////////////////////////////////////////////////
//  thread class that interacts with console
import java.lang.Thread;
import java.io.*;

public class Console extends Thread {


	public void run()
	{
		byte b[] =  new byte[200];

		int bites_in_buffer = 0;

		BufferedReader is = new BufferedReader (new InputStreamReader
(System.in));

		int bytes_read    = -1;
		while ( true )
		{
		   try{				
		    String command  = is.readLine();
		    if (command.length() == 0)
			break;	
			
                        // execute command 
                        // inform user about executing 
			System.out.println ("Executing command......");
                        // delay  
                         try{
				sleep (1000);
			 }
			 catch (InterruptedException e)
				{}
                        // print results 
			System.out.println ("Entered command : " + command);
			}
			catch (Exception e)
			{
				System.out.println (e);
			}
		}
System.out.println ("leaving thread ");
	}
	

public void die()
	{
	}

}

///////////////////////////////////////////////////////////////////////
// build.xml file
<project name="TEST" default="init" basedir=".">
    <description>
          build file
    </description>
  <!-- set global properties for this build -->

 <target name="compile">
    <javac srcdir="${basedir}" >
    </javac>
 </target>


 <target name="run-thread" depends="compile">
   <java classname="A" fork="true" >
       <classpath path="${basedir}"/>
   </java>
 </target>


 <target name="run-bat" depends="compile">
   <exec  executable="run-thread.bat">
   </exec>

 </target>

</project>

///////////////////////////////////////////////////////////////////////
//this is a body of run-thread.bat file

java A

///////////////////////////////////////////////////////////////////////
//

---------------------------------------------------------------------
To unsubscribe, e-mail: ant-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ant-dev-help@jakarta.apache.org


Mime
View raw message