The ant-java task needs to be inserted in order to capture the return code of whatever "body" it executes and report back to the user. That's why spawn is set to false. Also fork is set to true so that I can reconfigure
all sorts of options such as the maximum amount of memory for the body.

Usually the pluggable body is a simple piece of java but in this instance it happens to be yet another ant task that executes a program, in this case the jboss run.bat file. And I can't have the situation where the launcher
program doesn't complete until jboss is shutdown.

The strange thing is that this approach works absolutely fine on Ubuntu and on Mac OS X for the jboss run.sh
executable!




Here are some links to the source, although it might be a little too much to expect anybody to dive right into
the middle:

"class containing the parent startVm() method that runs the ant-java task"
http://code.google.com/p/protoj/source/browse/1.9.0/src/java/protoj/lang/DispatchFeature.java

"class containing the child startServer() method that runs the ant- exec task"
http://code.google.com/p/protoj/source/browse/1.9.0/src/resources/protoj/serverdemo/src/java/org/serverdemo/system/ServerDemoProject.java

"helpers for calling ant programatically"
http://code.google.com/p/protoj/source/browse/1.9.0/src/java/protoj/util/CommandTask.java
http://code.google.com/p/protoj/source/browse/1.9.0/src/java/protoj/util/AntTarget.java
http://code.google.com/p/protoj/source/browse/1.9.0/src/java/protoj/lang/command/StartVmCommand.java


Here is the



On 27 Apr 2009, at 18:50, glenn opdycke-hansen wrote:

Can you insert the Ant project that calls both the Java application and the
batch job?
If so, then you can use the parallel task, see
http://ant.apache.org/manual/CoreTasks/parallel.html


On Mon, Apr 27, 2009 at 12:42 PM, Ashley Williams <ashpub...@mac.com> wrote:

Ok here's a little more context.

It seems that the exec/spawn=true command works as expected when called on
its own directly from java.exe
but not from an intermediate ant java task, so:

1. GOOD... When I launch the cmd.exe from a programmatic ant exec task, the
exec task and java.exe both complete, and the dos window
remains until I close it ( I've left a large gap in the chain description
so it lines up with the next example):



  java.exe   --->
                ant-exec (spawn=true)   --->   cmd.exe
  (terminates before dos cmd.exe window is closed)


2. BAD... When I insert an programmatic ant java task, the exec task
appears to complete but the ant java task doesn't. Then when
I close the dos window the java.exe process completes also. This is despite
the ant-exec spawn attribute being true.



java.exe ---> ant-java (fork=true, spawn=false) ---> ant- exec
(spawn=true)   --->   cmd.exe
  (terminates only when dos cmd.exe window is closed)


I know it looks a little unusual to have the extra ant-java task in there
but it is necessary for my use-case and I don't have
the option to set spawn to true for it. Any ideas?

Many Thanks
- Ashley



On 24 Apr 2009, at 13:20, Ashley Williams wrote:

Hi,

I  would like to know how to start a batch file in a new dos window
without blocking the java process and so naturally I
tried the following that does work:

<project name="project" default="target" basedir=".">
<target name="target">
        <exec executable="cmd" spawn="true" dir="${basedir}">
          <arg value="/c"/>
          <arg value="start"/>
          <arg value="test.bat"/>
        </exec>
</target>
</project>

However I need to be able to do this from java and so I used the following
snippet of code that I thought would
represent the same functionality as the ant script:

public static void main(String[] args) throws IOException {
      // top level project
      Project project = new Project();
      project.setName("project");
      project.init();

      // project has a target child
      Target target = new Target();
      target.setName("target");
      project.addTarget(target);

      // target has an exec child
      ExecTask execTask = new ExecTask();
      execTask.setProject(project);
      target.addTask(execTask);
      execTask.setExecutable("cmd.exe");
      execTask.setSpawn(true);
      execTask.setDir(new File("."));
      addArg(execTask, "/c");
      addArg(execTask, "start");
      addArg(execTask, "test.bat");
      target.execute();
}

However it doesn't matter whether or not I set true of false for the spawn
property the java process blocks
every time until I close the dos window by hand. Is there something else I
need to do to more closely
replicate the ant script?

Cheers
- Ashley

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



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




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

Reply via email to