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 /////////////////////////////////////////////////////////////////////// //
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.
Has this been fixed in ant1.6, where we stream input to forked programs?