Bug 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
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.5.1
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-29 21:42 UTC by Aleksandr
Modified: 2008-11-24 03:57 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aleksandr 2003-01-29 21:42:18 UTC
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

///////////////////////////////////////////////////////////////////////
//
Comment 1 Stefan Bodewig 2003-01-30 10:19:38 UTC
input doesn't work with <exec> or <java fork="true">, this is a know limitation.

I'm surprised I cannot find any bug report that I could use to mark this one as
duplicate.
Comment 2 Steve Loughran 2006-06-27 18:09:40 UTC
Has this been fixed in ant1.6, where we stream input to forked programs?