You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by John Mazzitelli <ma...@comcast.net> on 2009/02/03 07:21:54 UTC

exec and the input hanging problem

I am hitting the bug where Ant hangs when doing an <exec> - see bug: 
https://issues.apache.org/bugzilla/show_bug.cgi?id=34461

I can't seem to get the workaround of using inputstring to work. I can 
replicate this bug, even when using inputstring="", on both Ant 1.6.5 
and Ant 1.7.1 - and I've seen this on both solaris and linux.

It's really simple to replicate - I'd appreciate it if someone can give 
me an idiot lesson on what I'm doing wrong, or tell me if I should 
submit another bug report on this.

1) Put the following three files in a directory (runjava.sh,  build.xml 
and Test.java - see below).
2) Compile Test.java via "javac Test.java".
3) Finally, just run "ant".

The ant script should complete very fast because runjava.sh puts the 
Java VM in background via "&". However, ant just hangs and will only die 
when the Java VM dies (which will be after a sleep of 60 seconds):

---runjava.sh---
java Test 60000 &

---build.xml---
<project name="test" default="do">
  <target name="do">
     <echo>Executing - this should go fast...</echo>
     <exec dir="." inputstring="" executable="/bin/sh">
       <arg line="runjava.sh"/>
     </exec>
     <echo>Execute finished.</echo>
  </target>
</project>

---Test.java---
public class Test {
  public static void main(String[] args) throws Exception {
     System.out.println("Java: sleeping");
     Thread.sleep(Long.parseLong(args[0]));
     System.out.println("Java: done sleeping");
  }
}


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


Re: exec and the input hanging problem

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-02-03, John Mazzitelli <ma...@comcast.net> wrote:

> I can't seem to get the workaround of using inputstring to work. I can
> replicate this bug, even when using inputstring="", on both Ant 1.6.5
> and Ant 1.7.1 - and I've seen this on both solaris and linux.

Because this time it is the output, not the input 8-(

If you change your runjava.sh to

java Test 60000 > /dev/null &

it will return immediately.

If you really want to spawn a process and forget about it (ignore its
input and output), use the spawn attribute of exec.  If OTOH you
really need th output, there is nothing you can do except waiting for
the forked process to finish.

Stefan

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