ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <jakarta-...@ehatchersolutions.com>
Subject Re: How to execute an interactive non-java program from an ant script ?
Date Wed, 15 May 2002 01:20:09 GMT
Have a look at the new <input> task and how its implemented... it might help
you out.

    Erik


----- Original Message -----
From: "KUMAR,PANKAJ (HP-Cupertino,ex1)" <pankaj_kumar@hp.com>
To: <ant-dev@jakarta.apache.org>
Cc: "KUMAR,PANKAJ (HP-Cupertino,ex1)" <pankaj_kumar@hp.com>
Sent: Tuesday, May 14, 2002 9:07 PM
Subject: FW: How to execute an interactive non-java program from an ant
script ?


> Forwarding to ant-dev as I didn't hear any suggestion on ant-user.
>
> Regards,
> Pankaj Kumar.
>
> PS: Please CC to me if you respond as I am not subscribed to ant-dev.
>
> > -----Original Message-----
> > From: KUMAR,PANKAJ (HP-Cupertino,ex1)
> > Sent: Monday, May 13, 2002 4:07 PM
> > To: 'ant-user@jakarta.apache.org'
> > Subject: How to execute an interactive non-java program from an ant
> > script ?
> >
> > Hi,
> >
> > I have a need to launch a text mode interactive non-java application
that
> > prompts user for text input . I looked at Exec task ( in Ant1.5Beta1 )
and
> > found that this doesn't take care of passing user input to the created
> > process. To address this I wrote a new task named ExecInteractive  by
> > deriving it from ExecTask and supplying my own MyPumpStreamHandler class
> > (implementing from ExecStreamHandler ). This handler creates three
> > separate threads that write the normal output of the new process to
> > System.out, error output to System.err and input from System.in to the
> > OutputStream associated with the process. The code run by each thread is
> > in class MyStreamPumper modeled after StreamPumper class ( all these are
> > in packacge org.apache.ant.taskdefs ).
> >
> > This works okay but with following problems:
> >
> > 1. Whenever the external program prompts the user for input and
terminates
> > the prompt string without a newline then nothing gets written on the
> > terminal. I changed my code in MyStreamPumper so that it would call
> > System.out.flush() after writing each byte. However, this causes each
> > character to be written on a separate line !! I beleive Ant is
processing
> > output through System.out and takes System.out.flush() as indication of
> > record termination.
> >
> > I have an ugly workaround for the time being -- I wrote a class
AntWrapper
> > that grabs the System.out and System.in in static variable and then
> > invokes the main() of Ant. I use these static variables in my
> > MyStreamPumper. To invoke ant, I call "java <package>.AntWrapper ...".
> >
> > Would prefer a better solution.
> >
> > 2. The second problem is more insidious. As I mentioned earlier,
> > MyPumpStreamHandler creates three threads: one for monitotring stdout of
> > the external program, one for stderr of the external program and one for
> > keyborad input ( by reading System.in ). When the external program
> > terminates then the thread monitoring the stdout and stderr of the
process
> > terminate but not the thread that is waiting for input on System.in. The
> > thread executing ExecStreamHandler is able to do a Thread.join() with
> > these two threads but is not able to interrupt the thread waiting for
> > keyboard input.
> >
> > My workaround is to ask the user ( from thread running the
> > MyPumpStreamHandler ) to hit ENTER. When the waiting thread reads this
and
> > tries to write to the stdin of the terminated process, it gets exception
> > and terminates itself.
> >
> > But I don't like this as it forces the user to do something unnecessary.
> >
> > Any help is most appreciated.
> >
> > Pankaj Kumar,
> > HP Middleware.
>
> --
> To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>
>
>


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


Mime
View raw message